I have created a custom hierarchical taxomony and when viewing a taxonomy archive page would like to only display the posts that have been assigned to that term. This works fine on the child term pages, but the parent term pages display posts assigned to them AND any child terms.
I found a solution that solves this for categories by inserting the following link after the beginning of the loop:
<? if ((is_category()) && in_category($wp_query->get_queried_object_id())) { ?>
But I haven't been able to find a similar solution that works for custom taxonomies.
I also tried:
function exclude_children($wp_query) {
if ( isset ( $wp_query->query_vars['custom_taxomony'] ) ) {
$wp_query->set('tax_query', array('include_children' => false));
}
}
add_filter('pre_get_posts', 'exclude_children');
But that does not seem to have any effect. So the question is, how do I do this?
tax_query
is supposed to take an array of arrays, so maybe try:$wp_query->set('tax_query', array( array('include_children' => false)));
– Dave Romsey Jun 14 '12 at 20:24