works only for custom query * filter: "ait_block_query_class" * action: "ait_blocks_query_before_post_content" * action: "ait_blocks_query_after_post_content" * action: "ait_blocks_recent_posts_no_posts" */ $attributes = $attributes ?? array(); $current_page = max( 1, get_query_var( 'paged', 1 ) ); $items_per_page = $query?->get( 'posts_per_page' ); $search_value = $query?->get( 's' ); $use_default_query = $attributes['defaultQuery']; if ( ! $use_default_query ) { $items_per_page = $attributes['numPosts'] ?? 5; $offset = ( $current_page - 1 ) * $items_per_page; $search_value = get_query_var( 's' ); $args = array( 'posts_per_page' => $items_per_page ); if ( ! empty( $attributes['usePagination'] ) ) { $args['offset'] = $offset; $args['paged'] = $current_page; } if ( ! empty( $attributes['isRelatedPosts'] ) && is_single() ) { $args['post_type'] = get_post_type(); $categories = get_the_category(); // get terms/categories $terms = get_the_terms( get_the_ID(), $attributes['taxonomy'] ?? 'category' ); if ( ! empty( $terms ) ) { $terms = array_map( fn( $cat ) => $cat->term_id, $terms ); $args['tax_query'] = array( array( 'taxonomy' => $attributes['taxonomy'] ?? 'category', 'field' => 'term_id', 'terms' => $terms, ), ); } $args['post__not_in'] = array( get_the_ID() ); } else { $args['post_type'] = $attributes['postType'] ?? 'post'; if ( ! empty( $attributes['category'] ) ) { $args['tax_query'] = array( array( 'taxonomy' => $attributes['taxonomy'] ?? 'category', 'field' => 'slug', 'terms' => $attributes['category'], ), ); } } if ( $attributes['useSearch'] && $search_value ) { $args['s'] = $search_value; } $args = apply_filters( 'ait_block_query_args', $args, $attributes['anchor'] ?? '' ); $query = new WP_Query( $args ); } $class_names = array( 'ait-query' ); if ( ! empty( $attributes['className'] ) ) { $class_names[] = $attributes['className']; } /** * filter: ait_block_query_class */ $class_names = apply_filters( 'ait_block_query_class', $class_names, $attributes['anchor'] ?? '' ); $posts_count = $query->found_posts; $total_pages = ceil( $posts_count / $items_per_page ); $get_page_url = function ( $page_num ) { return get_pagenum_link( $page_num ); }; if ( $attributes['showItemsFoundMessage'] ) : ?>
have_posts() ) : ?>