wordpress - WP_Query categories tree -


i have loop shows images specific category.

$args = array( 'posts_per_page' => 10,    'post_status' => 'inherit',  'post_type'=> 'attachment', 'cat' => 777 );   $wp_query = new wp_query($args); 

i'm looking posts in category both in categories descendants of category.thanks

you can use get_term_children(), first descendants of category. can pass list of term ids in query arguments, under category__in key:

$category_id = 777; $term_ids = get_term_children($category_id, 'category');  $args = array(     'posts_per_page' => 10,        'post_status' => 'inherit',      'post_type'=> 'attachment',     'category__in' => array($category_id) + $term_ids );  $wp_query = new wp_query($args); 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -