I'm using the Mini Loops plugin to display recent posts. When viewing a parent category it displays the posts from that category as well as any child categories. I would like to change this so only the posts assigned to the parent category are displayed.
After looking through the documentation for the plugin, I think it might be possible to use a filter to modify the plugin's output but I'm not sure exactly how to do it.
The following function is given in the documentation as an example of modifying the query based on tags:
/*
Modify the query args before they are run
Can either work on all instances, or only some by checking existing args
This demo changes the 'tag__in' query to 'tag__and' to limit the number of matching posts
*/
add_filter( 'miniloops_query' , 'miniloops_query_filter_test' );
function miniloops_query_filter_test( $query ) {
if ( $query['tag__in'] == array( 53, 82 ) ) {
$query['tag__and'] = $query['tag__in'];
unset( $query['tag__in'] );
}
return $query;
}
The function modifies the query argument but if the argument doesn't already exist can it be added rather than just modified? Not sure if this is even possible.
UPDATE: I added below what I think is the relevant section of code in the plugin file:
$tax_query = array();
foreach( array_keys( $taxes ) as $k => $slug ) {
//original code is this single commented line, if you need to revert
//$tax_query[] = array( 'taxonomy' => $slug, 'field' => 'id', 'terms' => explode( ',', $taxes[ $slug ] ) );
$oper = 'IN';
$ids = explode( ',', $taxes[ $slug ] );
if ( count( $ids ) == 1 && $ids['0'] < 0 ) {
//if there is only one id given, and it's negative
//let's treat it as 'posts not in'
$ids['0'] = $ids['0'] * -1;
$oper = 'NOT IN';
}
$tax_query[] = array(
'taxonomy' => $slug,
'field' => 'id',
'terms' => $ids,
'operator' => $oper );
}
I tried adding include_children => FALSE
but it didn't work.
Mini Loops
plugin.