WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. Laver2k
    Member
    Posted 3 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:

    <?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! :)

  2. MichaelH
    Member
    Posted 3 years ago #

  3. Laver2k
    Member
    Posted 3 years ago #

    Aah, I was using it incorrectly!
    Thanks :)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.