Include Sticky Posts in Page Post Count for custom query

I think we can try the following: (NOTE: This is untested but should in theory work, but remember, it is untested and can be buggy) add_action(‘pre_get_posts’, ‘ad_custom_query’); function ad_custom_query($query) { // No other checks should be necessary if ( $query->get( ‘custom_query’ ) === 1 ) ) { // set the number of posts per page … Read more

How to display the modified post today

You can use the date_query part of WP_Query. Here’s an example: $args = array ( ‘post_type’ => array( ‘post’ ), ‘post_status’ => array( ‘publish’ ), ‘category_name’ => ‘airing’, //<– N.B. This is for a category slug! ‘date_query’ => array( array( ‘column’ => ‘post_modified_gmt’, ‘after’ => ‘today’, ‘inclusive’ => true ), ) ); $query = new … Read more

How to prevent queried posts from being added to cache?

The posts array result in WP_Query is mapped to get_post() (here and here) with: $this->posts = array_map( ‘get_post’, $this->posts ); and that seems to be adding posts to the object cache even though the cache_results argument is set to false in WP_Query. Within the get_post() function (here) we have: $_post = WP_Post::get_instance( $post ); for … Read more

How to use order RAND() on WordPress?

You are right that you can’t have WordPress order the retrieved posts randomly. So you’ll have to do that yourself after you have retrieved the array of post objects. Let’s call that $my_posts. Because you don’t know how many of the posts in that array are featured, you will have to loop through them to … Read more

Query posts with more than 20 comments

WP_Query does not currently support querying by the comment_count field, but there is a proposed patch for this functionality. See Trac ticket #28399. Update: #28399 has been fixed and should land in version 4.9 In the meantime, here is a workaround based on information from this post which will alter the where clause of a … Read more