Avoiding page loop

I would highly recommend you to make one of those wp query calls the main query & all others as secondary queries. That will make your life much easier in the long run. If you absolutely want to disable the main query, wordpress doesn’t have a direct filter for that. You can however do a … Read more

How to check during “pre_get_posts” if WP performing default query for specific custom template?

As you describe the timing would not quite work. During WP core load: main query is created and processed into query variables (with pre_get_posts being one of the hooks able to influence the results) then template-loader.php uses conditionals (dependent on those query variables) to determine template to use So at the point of pre_get_posts you … Read more

Get query result before posts are displayed?

You can use the the_posts filter to loop through the results before they get returned. Proof of concept: function test_the_posts($a) { var_dump($a); die; } add_action(‘the_posts’,’test_the_posts’); I am fairly certain (though I haven’t tested it) that you could pretty easily break pagination and probably other things by fiddling with that, so be careful.

pre_get_posts redirecting

you can allow only registered user to see your content by 1.this solution for post show only to login user class RavsPublic { function __construct() { add_action(‘pre_get_posts’, array($this, ‘try_redirect’)); } function try_redirect( $query ) { // not on home page and not login if( !is_home() && !is_user_logged_in() ){ // send them to home page wp_redirect( … Read more

Set posts per page for parent category and it’s all children

You want get_term_children. function hbg_category_query( $query ) { if( $query->is_main_query() && $query->is_category()) { $categories = get_term_children(1,’category’); $categories[] = 1; // add your special category if (is_category($categories)) { $query->set( ‘posts_per_page’, 32 ); } } return $query; } add_action(‘pre_get_posts’,’hbg_category_query’); Barely tested, but I think that will work.