This is an overly complicated approach. pre_get_posts
will work for any query and there are numerous ways to control when/how the callback behaves:
-
Add and remove the callback:
function dummy_action($q) { } add_action('pre_get_posts','dummy_action'); $q = new WP_Query( array( 'post_type' => 'post' ) ); remove_action('pre_get_posts','dummy_action');
-
Use a self-removing callback:
function dummy_action($q) { remove_action('pre_get_posts','dummy_action'); } add_action('pre_get_posts','dummy_action'); $q = new WP_Query( array( 'post_type' => 'post' ) );
-
Feed the query a parameter you can use as a trigger:
function dummy_action($q) { if ($q->get('action_trigger')) { // do something } } add_action('pre_get_posts','dummy_action'); $q = new WP_Query( array( 'post_type' => 'post', 'action_trigger' => true ) );
You do not want to “assign” a secondary query as the main query. That will cause the same issues as caused by using query_posts()
, which essentially does assign a secondary query as the main query.