Combine pre_get_posts into one query
-
I’m using two pre_get_posts to set two queries. I would like to have one query but don’t know if it’s possible.
function exclude_category( $query ) { if ( $query->is_home() && $query->is_main_query() ) { $query->set('tax_query', array(array('taxonomy' => 'category','field' => 'slug','terms' => array( 'podcast-control-daily' ),'operator'=> 'NOT IN'),array('taxonomy' => 'post_format','field' => 'slug','terms' => array( 'post-format-status' ),'operator'=> 'NOT IN'))); $query->set( 'posts_per_page', 15 ); } return $query;} add_action( 'pre_get_posts', 'exclude_category' ); function ctrl_daily_posts( $query ){ if( $query->get( 'ctrl_daily' ) == 'posts' ){ $query->set( 'tax_query', array(array('taxonomy' => 'category','field' => 'slug','terms' => array( 'podcast-control-daily' ),'operator'=> 'IN'))); $query->set( 'posts_per_page', 5 ); } } add_action( 'pre_get_posts', 'ctrl_daily_posts', 10 );
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- The topic ‘Combine pre_get_posts into one query’ is closed to new replies.