Change default query using request filter
-
I working on a site with heavy traffic so expensive queries are avoided by not using query_posts since it tosses the orig query. I need a way to filter the request to alter the query before it fires and make it only apply to only a category and not interfere with other pages. I’m using something similar to:
function alter_the_query( $request ) { $dummy_query = new WP_Query(); // the query isn't run if we don't pass any query vars $dummy_query->parse_query( $request ); switch_to_blog(10) // this is the actual manipulation; do whatever you need here if ( $dummy_query->is_home() ) $request['category_name'] = 'news'; return $request; } add_filter( 'request', 'alter_the_query' );
The problem is that this query runs for every archive page (which interferes with search page and other pages). I need a way to make it only apply to the category.php page and then a way to filter for archive.php and others. In this case is_category and is_archive do not work.
Any suggestions are appreciated.
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- The topic ‘Change default query using request filter’ is closed to new replies.