• Resolved yakuter

    (@yakuter)


    How can I add this to normal WordPress query (loop)

    post_title LIKE ‘$letter%’

    I don’t want to use plugin or custom select so can we just put at in the normal loop?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Something along these lines

    $letter = 'the string I'm looking for';
    if (have_posts()) :
    while (have_posts()) : the_post();
    if ( stripos($post->post_content, $letter) ) {
    //display your post stuff
    } //end if stripos
    endwhile;
    } //end if have posts

    Thread Starter yakuter

    (@yakuter)

    Thanks Micheal for your help but I have a pagination (pagebar plugin) and I want it work when I click A letter for example. By code you give above paginations still gets all the posts but I need to make it get only posts starts with “A”. This should be less number of posts.

    I saw some filters like posts_where but I couldn’t make it.

    Not sure I’m helping you but look at the substr function.

    Thread Starter yakuter

    (@yakuter)

    Thanks a lot for your help. I solved the problem like this;

    function arabunu ()
    {
    global $wpdb;
    $sorgu= "AND $wpdb->posts.post_status='publish'
    AND $wpdb->posts.post_type='post'
    AND $wpdb->posts.post_title LIKE '".$_SESSION["harf"]."%'";
    return $sorgu;
    }
    add_filter('posts_where', 'arabunu');

    Okay, you are promoted to WordPress guru. Thanks for the answer ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Adding post_title LIKE ‘$letter%’’ is closed to new replies.