Support » Fixing WordPress » How use the LIKE in query_posts

  • Resolved lucaswxp


    Hello everybody!
    I’m having a problem.
    I want to set the LIKE in query_posts, something like that:

    query_posts(array('like' => 'something%', 'posts_per_page' => 5))

    How can I do this?
    Bye o/

Viewing 7 replies - 1 through 7 (of 7 total)
  • There is no “like” parameter in query_posts.

    yes, but, I want to know if I can do something with the same effect of “LIKE”, because I’m offering a list to my users:
    A - B - C - D - E - F -...
    So… when the user click on “A” for exemple, will list posts that start with this letter. I thought to use de the $wpdb->get_results(), but that way I will have to do the pagination manually… (using LIMIT and OFFSET)

    You can use a filter to add a condition to the where clause of the query. I don’t know the variable that holds the chosen letter, but assume it is $letter. Use this code just ahead of your query_posts:

    function mam_posts_where ($where) {
       global $mam_global_where;
       if ($mam_global_where) $where .= " $mam_global_where";
       return $where;
    $mam_global_where = "AND $wpdb->posts.post_title LIKE '$letter%'";

    Thnkx “vtxyzzy” @.@

    Glad it worked! Now, please use the dropdown at top right to mark this topic ‘Resolved’.

    Is there any way to explain this in more universal terms? I’m not sure what the terms of his specific situation are and what I would need to use and what I would need to replace with my own terms.

    But I have a similar situation, I want to organize local bands and people can click on “A” and find a list of all the bands whose name starts with the letter A. Then you can click on “B” to find a list of all the bands that start with the letter B. Etc…

    You should start a new thread with this question. You normally do not get responses to a ‘Resolved’ thread.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘How use the LIKE in query_posts’ is closed to new replies.