Alter query using pre_get_posts() if meta_key is present

Based on data from your Gist, the following pre_get_posts condition should work to limit your posts per page. add_action( ‘pre_get_posts’, ‘my_set_category_posts_per_page’ ); function my_set_category_posts_per_page() { global $wp_query; if ( ‘category_sticky_post’ === $wp_query->query_vars[‘meta_key’] ) { $wp_query->set( ‘posts_per_page’, 8 ); } }

Loop Split two Columns

How can one split a loop via WP_Query into two columns without having to work with two loops These would be possible with if conditional. and it is possible that for example in the left side those posts of category “A and B” and in the right side those posts of category “C and D … Read more

Get all posts including sticky ones with get_posts(),setup_postdata(), and foreach loop?

Updated answer: The default behavior of WP is exactly what you want. The problem is that you are using get_posts() which completely ignores the sticky post behavior by forcing ignore_sticky_posts = true (check the source). So you need only one query, just use WP_Query(): $postsList = new WP_Query([ ‘post_type’ => ‘post’, ‘posts_per_page’ => $default_posts_per_page, ‘paged’ … Read more