0

I have a category and will query posts from 2 different child categories see below.

This is my structure

1 category
  - 1.1 category <- her we are (on this category i will show the posts from 1.1.1 and 1.1.2)
    -- 1.1.1 category <- In this category are the posts
    -- 1.1.2 category <- And this category are the posts

2 category
  - 2.1 category
    -- 2.1.1 category
    -- 2.1.2 category

Thx for help.

2
  • Which categories you want to get posts from? Please explain your question better by editing it.
    – Robert hue
    Commented Nov 5, 2014 at 11:33
  • I edit the question. I will get posts from 1.1.1 & 1.1.2
    – Rene
    Commented Nov 5, 2014 at 11:37

1 Answer 1

0

To include posts from one or more specific categories, you can use and define category__in parameter in your WordPress query. Like this, here is an example.

$args = array(
    'category__in' => array( 11, 15 ),
);

$my_query = new WP_Query( $args );

if ( $my_query->have_posts() ) :
    while ( $my_query->have_posts() ) : $my_query->the_post();

        get_template_part( 'content', get_post_format() );

    endwhile;
endif;

wp_reset_postdata();

Where 11, 15 are the category ids of the categories that you want to include posts from. You can add as many categories as you want. You just have to add comma separated ids of those categories.

3
  • Ok i will try this. Thx for now.
    – Rene
    Commented Nov 5, 2014 at 11:45
  • Thx it works perfectly, many many thx i wasted many hour for this yesterday.
    – Rene
    Commented Nov 5, 2014 at 12:33
  • You did not waste your time. That's how we learn. First you try and search for a solution and if you are not still not able to get it right, ask here. :)
    – Robert hue
    Commented Nov 5, 2014 at 13:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.