build_query_vars_from_query_block example


        add_filter( 'next_posts_link_attributes', $filter_link_attributes );
        // Take into account if we have set a bigger `max page`         // than what the query has.         global $wp_query;
        if ( $max_page > $wp_query->max_num_pages ) {
            $max_page = $wp_query->max_num_pages;
        }
        $content = get_next_posts_link( $label$max_page );
        remove_filter( 'next_posts_link_attributes', $filter_link_attributes );
    } elseif ( ! $max_page || $max_page > $page ) {
        $custom_query           = new WP_Query( build_query_vars_from_query_block( $block$page ) );
        $custom_query_max_pages = (int) $custom_query->max_num_pages;
        if ( $custom_query_max_pages && $custom_query_max_pages !== $page ) {
            $content = sprintf(
                '<a href="%1$s" %2$s>%3$s</a>',
                esc_url( add_query_arg( $page_key$page + 1 ) ),
                $wrapper_attributes,
                $label
            );
        }
        wp_reset_postdata(); // Restore original Post Data.     }
    
global $wp_query;
    if ( isset( $block->context['query']['inherit'] ) && $block->context['query']['inherit'] ) {
        // Take into account if we have set a bigger `max page`         // than what the query has.         $total         = ! $max_page || $max_page > $wp_query->max_num_pages ? $wp_query->max_num_pages : $max_page;
        $paginate_args = array(
            'prev_next' => false,
            'total'     => $total,
        );
        $content       = paginate_links( $paginate_args );
    } else {
        $block_query = new WP_Query( build_query_vars_from_query_block( $block$page ) );
        // `paginate_links` works with the global $wp_query, so we have to         // temporarily switch it with our custom query.         $prev_wp_query = $wp_query;
        $wp_query      = $block_query;
        $total         = ! $max_page || $max_page > $wp_query->max_num_pages ? $wp_query->max_num_pages : $max_page;
        $paginate_args = array(
            'base'      => '%_%',
            'format'    => "?$page_key=%#%",
            'current'   => max( 1, $page ),
            'total'     => $total,
            'prev_next' => false,
        );


    $page_key = isset( $block->context['queryId'] ) ? 'query-' . $block->context['queryId'] . '-page' : 'query-page';
    $page     = empty( $_GET[ $page_key ] ) ? 1 : (int) $_GET[ $page_key ];

    // Override the custom query with the global query if needed.     $use_global_query = ( isset( $block->context['query']['inherit'] ) && $block->context['query']['inherit'] );
    if ( $use_global_query ) {
        global $wp_query;
        $query = $wp_query;
    } else {
        $query_args = build_query_vars_from_query_block( $block$page );
        $query      = new WP_Query( $query_args );
    }

    if ( $query->have_posts() ) {
        return '';
    }

    if ( ! $use_global_query ) {
        wp_reset_postdata();
    }

    

function render_block_core_post_template( $attributes$content$block ) {
    $page_key = isset( $block->context['queryId'] ) ? 'query-' . $block->context['queryId'] . '-page' : 'query-page';
    $page     = empty( $_GET[ $page_key ] ) ? 1 : (int) $_GET[ $page_key ];

    // Use global query if needed.     $use_global_query = ( isset( $block->context['query']['inherit'] ) && $block->context['query']['inherit'] );
    if ( $use_global_query ) {
        global $wp_query;
        $query = clone $wp_query;
    } else {
        $query_args = build_query_vars_from_query_block( $block$page );
        $query      = new WP_Query( $query_args );
    }

    if ( ! $query->have_posts() ) {
        return '';
    }

    if ( block_core_post_template_uses_featured_image( $block->inner_blocks ) ) {
        update_post_thumbnail_cache( $query );
    }

    
Home | Imprint | This part of the site doesn't use cookies.