diff --git a/php/Block.php b/php/Block.php index bc270e4..ce17920 100644 --- a/php/Block.php +++ b/php/Block.php @@ -63,66 +63,94 @@ public function register_block() { * @return string The markup of the block. */ public function render_callback( $attributes, $content, $block ) { - $post_types = get_post_types( [ 'public' => true ] ); - $class_name = $attributes['className']; + $post_types = get_post_types( [ 'public' => true ], 'objects' ); + $class_name = sanitize_html_class( $attributes['className'] ?? '' ); + $current_id = get_the_ID(); ob_start(); ?> -
-

Post Counts

+
+

+ +

['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

- + 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; + ?> +

+ +