Toni Michel Caubet Toni Michel Caubet - 2 months ago 9
PHP Question

WP query to get posts from category ( not child of it )

I have this $args for WP_Query:

$args = array(
'post_type' => 'estructura',
'tax_query' => array(
array(
'taxonomy' => 'category',
'field' => 'term_id',
'terms' => '12',
),
)
);


Witch returns the posts tagged with the category 12 or tagged with the childs categories ( of 12 )

I want only the ones tagged with category 12,

How can I prevent to return the childs?

Thanks!

Answer

I was able to solve this problem using the include_children option

$args = array(
    'post_type' => 'estructura',
    'tax_query' => array(
        array(
            'taxonomy' => 'category',
            'field'    => 'term_id',
            'terms'    =>  $tax_id, // 12
            'include_children' => false
        )
    )
);