0

My website is in Swedish and i will write about different kind of topics. In sweden we have these kind of characters too ö, ä & å. I have created a page where i will show only CPT posts that start with character A. The problem that i am now getting is that

When showing posts that start with Ä then it also shows posts starting with A & Å. Same thing if i for example want to show posts starting with O then it shows posts starting with Ö also.

How do i go about to filter out right.



Here is my code

    <?php
//get all post IDs for posts start with letter A, in title order,
//display posts
global $wpdb;
$char_a = 'A';


$postids = $wpdb->get_col($wpdb->prepare("
SELECT      ID
FROM        $wpdb->posts
WHERE       SUBSTR($wpdb->posts.post_title,1,1) = %s
ORDER BY    $wpdb->posts.post_title",$char_a)); 

if ($postids) {
$args=array(
  'post__in' => $postids,
  'post_type' => 'encyklopedi',
  'post_status' => 'publish',
  'posts_per_page' => -1,
  // 'caller_get_posts'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
 // echo 'List of Posts Titles beginning with the letter '. $char_a;
  while ($my_query->have_posts()) : $my_query->the_post(); ?>
    <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent 

Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
<?php endwhile; } else { ?>
    <p><?php _e( 'Kunde inte hitta några inlägg som börjar med A...' ); ?></p>
<?php }
wp_reset_query(); } ?>

Is it maybe only something that i should do in $char_a = 'Here'; or maybe something in functions too ?

Stack ant
  • 51
  • 7
  • You could try converting your database's character set from UTF-8 (typical default in mySQL) to swe7(The Swedish character set.) Never messed with character sets specifically for WordPress, so... this might break things horribly so make sure your backup is good. – Nosajimiki Aug 14 '17 at 20:00
  • 1
    CORRECTION: use utf8_swedish_ci. I believe swe7 may be obsolete. – Nosajimiki Aug 14 '17 at 20:02

0 Answers0