I’m trying to replace the $wp_query
object for a specific category, without having to deal with creating a new template and creating a new WP_Query
object there.
My aim is to change the data available to The Loop from the default for that request to a custom query.
add_filter( 'pre_get_posts', 'custom_wpquery' );
function custom_wpquery( $query ){
global $wp_query;
if (is_category(121)) {
if ($wp_query === $query) {
$query = new WP_Query('page_id=146');
$query->set('page_id', 146);
}
}
return $query;
};
That doesn’t seem to affect The Loop at all, what am I doing wrong?