• I am trying to use ‘get_posts’ to pick up posts that are in two categories. Currently I am using this:
    $myposts = get_posts('numberposts=1&category=4&category=7');

    This picks up posts that are either in category 4 or 7. The posts I want to pick up must be in both categories at once. Any suggestions?

Viewing 4 replies - 1 through 4 (of 4 total)
  • http://wordpress.org/support/topic/339108?replies=2

    im not so familiar, but does the comma work?

    $myposts = get_posts('numberposts=1&category=4,7');

    all the examples I keep finding have to do with query_posts and I’m not sure if the examples help at all…like:
    query_posts(array('category__and' => array(4,7)));

    Thread Starter fangonk

    (@fangonk)

    Nope Commas don’t do it but thanks 😉 The other solution doesn’t work because I am working with multiple sets of categories in a single template, thus I can’t put it outside the template.

    $myposts = get_posts('numberposts=1&category=4&&category=7');

    Now I’m totally digging….this is my last attempt, and I’ll leave this to those more knowledgeable than I…. 😉

    Thread Starter fangonk

    (@fangonk)

    Meh, I just wussed out and created an ugly working around using a lot of extra categories. Thanks for giving it a look!

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Get posts that are in 2 galleries’ is closed to new replies.