[resolved] How to return posts belonging to multiple categories? (3 posts)

  1. Laver2k
    Posted 5 years ago #

    Hey all,

    I'm trying to create a portfolio with submenu sections such as 'web design' 'graphic design' etc.

    I have labelled my posts with the categories 'Portfolio' and a type like 'Web Design'.

    I have made a general page template for all of the sections to share. I'm aiming to get the content to change based on which page is selected and then swapping in the category name in to the loop.

    So this is what I'm using to create a variable based on which page is selected and it works fine:

    if ( is_page('web-design') ) { $current = 'Web Design'; }
    elseif ( is_page('photography') ) { $current = 'Photography'; }
    elseif ( is_page('graphicdesign') ) { $current = 'Graphic Design'; }
    elseif ( is_page('other') ) { $current = 'Other'; }

    This is the tricky part. I want to use category__and but I have heard this was broken recently.
    Question: How can I return posts belonging to *both* categories 'Portfolio' AND a category returned by $current?

    This is my current code that returns just the portfolio category's posts:
    $latestPortfolio = new WP_Query();
    <?php while ($latestPortfolio->have_posts()) : $latestPortfolio->the_post(); ?>

    I would really appreciate any help anyone can offer! :)

  2. MichaelH
    Posted 5 years ago #

  3. Laver2k
    Posted 5 years ago #

    Aah, I was using it incorrectly!
    Thanks :)

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.