• Resolved paa1605

    (@paa1605)


    Hi guys,

    I need some help in displaying posts that are in TWO categories. What makes it a little tricky is that i’m trying to write some code that asks wordpress to show posts that are in the category of ‘best-sellers’ AND the category ID of the current page. For example, if i was on the category archive page of ‘sport’, i would like wordpress to get the category ID of that page, and then display posts that are in that category, and also in the category of ‘best-sellers’. The result would therefore be a page showing best selling sport products (posts). Can anyone help me in achieving this? Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    In the following examples the ‘best-sellers’ category has an ID of 6. change this to the actual category ID.

    Display posts that are in multiple categories. (current category and best-sellers category):

    <?php
    $current_category = get_query_var('cat');
    query_posts(array('category__and' => array($current_category, 6)));
     ?>

    Display posts from several specific category IDs (current category or best-sellers category):

    <?php
    $current_category = get_query_var('cat');
    query_posts('cat=6,'.$current_category);
     ?>

    Thread Starter paa1605

    (@paa1605)

    Thanks very much! Worked a treat!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to shows posts that are in two categories?’ is closed to new replies.