Why my query is not "Main_query"?

I made a new page in admin panel like this. I want my Query here to be main_query so the other plugins could hook it, modify limits, etc...

add_action('admin_menu', function (){
    add_submenu_page('edit.php?post_type=ticket', __('Board', 'askanban'), __('Board', 'askanban'), 'edit_posts', 'askanban', array( $this, 'askanban_display_board' ), 1);
});

public function askanban_display_board(){
        $args = array(
            'post_type'              = 'ticket',
            'posts_per_page'         = - 1,
        );
        $query =  new \WP_Query( $args );
        $query-is_main_query(); // FALSE HERE!!!!!!!
        $posts = $query-posts;
        print_r($posts);
}

I read tons of info like this How to know which one is the main query? , this https://wp-qa.com/can-i-set-my-wp_query-to-be-a-main-query or When should you use WP_Query vs query_posts() vs get_posts()? I tried to use get_posts() and even tried to set $GLOBALS['wp_query'] = new \WP_Query( $args ) or $GLOBALS['wp_the_query'] = new \WP_Query( $args ); Noting helps. The other plugin can't see this query as main. For this other plugin there is no main query on this page. Why?

Topic get-posts wp-query Wordpress

Category Web


And the anwser to my question: Don't make new WP_Query object. Don't try to overwrite main query. Use global $wp_query; In my example the function should be like this:

public function askanban_display_board(){
    global $wp_query;
    $wp_query->set('post_type', 'ticket');
    $wp_query->set('posts_per_page', -1);
    $posts = $wp_query->get_posts();
    print_r($posts);
}

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.