wp_reset_postdata example

$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();
    }

    $classes            = ( isset( $attributes['style']['elements']['link']['color']['text'] ) ) ? 'has-link-color' : '';
    $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classes ) );
    return sprintf(
        '<div %1$s>%2$s</div>',
        $wrapper_attributes,
        $content
    );
}

// Wrap the render inner blocks in a `li` element with the appropriate post classes.         $post_classes = implode( ' ', get_post_class( 'wp-block-post' ) );
        $content     .= '<li class="' . esc_attr( $post_classes ) . '">' . $block_content . '</li>';
    }

    /* * Use this function to restore the context of the template tags * from a secondary query loop back to the main query loop. * Since we use two custom loops, it's safest to always restore. */
    wp_reset_postdata();

    return sprintf(
        '<ul %1$s>%2$s</ul>',
        $wrapper_attributes,
        $content
    );
}

/** * Registers the `core/post-template` block on the server. */
$draft_or_post_title
            );
        }

        echo '</ul>';
        echo '</div>';

    } else {
        return false;
    }

    wp_reset_postdata();

    return true;
}

/** * Show Comments section. * * @since 3.8.0 * * @param int $total_items Optional. Number of comments to query. Default 5. * @return bool False if no comments were found. True otherwise. */

function wp_reset_query() {
    $GLOBALS['wp_query'] = $GLOBALS['wp_the_query'];
    wp_reset_postdata();
}

/** * After looping through a separate query, this function restores * the $post global to the current post in the main query. * * @since 3.0.0 * * @global WP_Query $wp_query WordPress Query object. */
function wp_reset_postdata() {
    
 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.     }
    return $content;
}

/** * Registers the `core/query-pagination-next` block on the server. */
function register_block_core_query_pagination_next() {
    register_block_type_from_metadata(
        __DIR__ . '/query-pagination-next',
        array(
            

            $paginate_args['add_args'] = array( 'cst' => '' );
        }
        // We still need to preserve `paged` query param if exists, as is used         // for Queries that inherit from global context.         $paged = empty( $_GET['paged'] ) ? null : (int) $_GET['paged'];
        if ( $paged ) {
            $paginate_args['add_args'] = array( 'paged' => $paged );
        }
        $content = paginate_links( $paginate_args );
        wp_reset_postdata(); // Restore original Post Data.         $wp_query = $prev_wp_query;
    }
    if ( empty( $content ) ) {
        return '';
    }
    return sprintf(
        '<div %1$s>%2$s</div>',
        $wrapper_attributes,
        $content
    );
}

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