Support » Fixing WordPress » help with query_posts

  • Resolved cybershot

    (@cybershot)


    I am trying to get a custom loop going based on the categories that are chosen. Right now, the loop shows all posts in every category. I have three categories set up.

    lunch, blog, menu

    Right now, lunch has 3 posts, blog has 1, and menu has 0

    Here is how I am tryin to do it.

    //getting the categories
    $cats = explode(' ', $data['blog_cats']);
    //seperating them by a comma
    $cats = implode(',',$cats);
    
    //adding single quotes to the categories
    $string = "'$cats'";
    //performing the query
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts(array('cat=' => $string,'showposts'=> 2,'order'=>'ASC','paged'=>$paged));

    I have tried many different ways, The one above is just the latest. If I print out the string, I do get ‘blog, lunch’ which is what I would expect to get. After reading the codex and looking at other code, I cannot figure out why it won’t work. Can you help?

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘help with query_posts’ is closed to new replies.