i would change the main query on a CPT archive page
the CPT is declare as "events", the name of the archive page I use is called 'archive-events.php" and this simple code won't work.
add_filter( 'pre_get_posts', 'pre_get_post_fct' );
function pre_get_post_fct( $wp_query ) {
if( $wp_query->is_main_query() ) :
echo "A";
endif;
}
The thing is, I don't understand why it doesn't echo "A". I probably miss something....
Could you help me please ? Thanks !
A
will be output in a place that's visible on the frontend without viewing source, and the filter your shared runs on all queries that are the main query. I suspect though that you've placed that filter insidearchive-events.php
which is far too late. Adding filters inside a theme template is a general anti-pattern and rarely works