• Resolved Laver2k

    (@laver2k)


    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:

    <?php
    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:
    <?php
    $latestPortfolio = new WP_Query();
    $latestPortfolio->query(‘category_name=portfolio&showposts=5’);?>
    <?php while ($latestPortfolio->have_posts()) : $latestPortfolio->the_post(); ?>

    I would really appreciate any help anyone can offer! 🙂

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to return posts belonging to multiple categories?’ is closed to new replies.