Insert/sticky specific post into Loop at specific location

This took a bit of trial and error but I think I got it. I was getting an infinite loop until I added suppress_filters. After that it was short work. function insert_post_wpse_96347($posts) { global $wp_query; $desired_post = 151; if (is_main_query() && is_home() && 0 == get_query_var(‘paged’)) { $p2insert = new WP_Query(array(‘p’=>$desired_post,’suppress_filters’=>true)); $insert_at = 3; if … Read more

SQL Statement generated by WP_Query not producing expected results

It looks like this section: AND (wptom_posts.post_status=”publish” OR wptom_posts.post_author = 1 AND wptom_posts.post_status=”private”) is not tied in at all to the two different query conditions… Perhaps the original code should be three conditions for part 1: array( ‘relation’ => ‘AND’, array( ‘taxonomy’ => ‘category’, ‘field’ => ‘slug’, ‘operator’ => ‘IN’), array( ‘taxonomy’ => ‘post_tag’, ‘field’ … Read more

Multiple orderby parameters in pre_get_posts() action

Never forget that there’re actually two filters // Add additional query args that are allowed by the API by default pre_get_posts // Modify the query herself posts_clauses // Inspect the resulting string – test this one in for e.g. phpMyAdmin posts_request So everything you can achieve using the pre_get_posts filter should be done there. The … Read more

Varying the number of posts per page from the first one

Thanks to s_ha_dum for the tip. I managed to solve it by setting the offset parameter in the special case of 2nd page onwards for the front page as follows: function limit_posts_per_home_page() { $paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1; $first_page_limit = 5; $limit = get_option(‘posts_per_page’); if (is_front_page()) { if ($paged == 1) { $limit … Read more