Replies: 0
I’m using a plugin to display recent posts in a widget. On parent category pages I want to prevent child category posts from being displayed.
Is it possible to modify the plugin’s custom query using pre_get_posts
? I tried the following code but couldn’t get it to work:
function child_posts_filter($query) {
if ( !$query->custom_query )
return $query;
$taxquery = array( 'include_children' => 0 );
$query->set( 'tax_query', $taxquery );
}
add_action( 'pre_get_posts', 'child_posts_filter' );
-
This topic was modified 1 hour, 11 minutes ago by
jrcollins.