+
- $post_type_slug,
- 'posts_per_page' => -1,
- ]
- )
- );
-
+ $post_type_object ) :
+ $post_type_object = get_post_type_object( $post_type_slug );
+ $post_count = wp_count_posts( $post_type_slug )->publish;
+ ?>
+
+ - labels->name ); ?>
+
- - labels->name . '.'; ?>
-
-
+
+
['post', 'page'],
- 'post_status' => 'any',
- 'date_query' => array(
- array(
- 'hour' => 9,
- 'compare' => '>=',
- ),
- array(
- 'hour' => 17,
- 'compare'=> '<=',
- ),
- ),
- 'tag' => 'foo',
- 'category_name' => 'baz',
- 'post__not_in' => [ get_the_ID() ],
- ));
- if ( $query->have_posts() ) :
- ?>
-
5 posts with the tag of foo and the category of baz
-
- posts, 0, 5 ) as $post ) :
- ?>- post_title ?>
-
+ if ( false === $query ) {
+ $query = new WP_Query( array(
+ 'post_type' => ['post', 'page'],
+ 'post_status' => 'any',
+ 'posts_per_page' => 6, // Total posts plus count of excluded posts.
+ 'no_found_rows' => true,
+ 'update_post_meta_cache' => false,
+ 'update_post_term_cache' => false,
+ 'date_query' => array(
+ array(
+ 'hour' => 9,
+ 'compare' => '>=',
+ ),
+ array(
+ 'hour' => 17,
+ 'compare' => '<=',
+ ),
+ ),
+ 'tax_query' => array(
+ 'relation' => 'AND',
+ array(
+ 'taxonomy' => 'category',
+ 'field' => 'slug',
+ 'terms' => 'baz',
+ 'include_children' => false,
+ ),
+ array(
+ 'taxonomy' => 'post_tag',
+ 'field' => 'slug',
+ 'terms' => 'foo',
+ ),
+ ),
+ ));
+
+ // Since we are dealing with large set of data here, We can store the entire query result in the cache group.
+ wp_cache_set( 'sc_baz_foo_filtered_posts', $query, 'site_counts' );
+ }
+
+ if ( $query->have_posts() ) :
+ $post_count = 0;
+ ?>
+
+
+ have_posts() ) :
+ $query->the_post();
+ if ( $current_id !== get_the_ID() && $post_count < 5 ) {
+ $post_count++;
+ ?>
+
+
+
+