我'm trying to show some custom filtered products list in a custom post type single view. I' ve扩展了 archive-product.php 文件并用 woobadge_query_filtered_products() 函数替换了 woocommerce_product_loop() 函数,该函数使用一些自定义过滤参数生成/设置全局 query_posts .
然后我只是使用 have_post()the_post() 函数来输出产品 . 我手动尝试在URL中使用 page 参数,看到分页工作正常 .
But the problem is pagination isn't present in the view.

模板代码如下:

<?php
/**
 * The Template for displaying product badge archives.
 * This template can be overridden by copying it to yourtheme/woocommerce/woobadge-archive-product.php
 */

defined( 'ABSPATH' ) || exit;

get_header( 'shop' );

/**
 * Hook: woocommerce_before_main_content.
 *
 * @hooked woocommerce_output_content_wrapper - 10 (outputs opening divs for the content)
 * @hooked woocommerce_breadcrumb - 20
 * @hooked WC_Structured_Data::generate_website_data() - 30
 */
do_action( 'woocommerce_before_main_content' );

// Show filter if enabled
if (vp_option('woo_badge_man_opt.pba_show_filters')) {
    echo do_shortcode('[woo_pro_badges_filter_archive_extended]');
}

?>
    <header class="woocommerce-products-header">
        <?php if ( apply_filters( 'woocommerce_show_page_title', true ) ) : ?>
            <h1 class="woocommerce-products-header__title page-title">Products Archive By `<?php the_title(); ?>`</h1>
        <?php endif; ?>

        <?php the_content(); ?>
    </header>
<?php
// Initiate filtered products query
if ( woobadge_query_filtered_products() ) {

    /**
     * Hook: woocommerce_before_shop_loop.
     *
     * @hooked wc_print_notices - 10
     * @hooked woocommerce_result_count - 20
     * @hooked woocommerce_catalog_ordering - 30
     */
    do_action( 'woocommerce_before_shop_loop' );

    woocommerce_product_loop_start();

        while ( have_posts() ) {
            the_post();

            /**
             * Hook: woocommerce_shop_loop.
             *
             * @hooked WC_Structured_Data::generate_product_data() - 10
             */
            do_action( 'woocommerce_shop_loop' );

            wc_get_template_part( 'content', 'product' );
        }

    woocommerce_product_loop_end();

    /**
     * Hook: woocommerce_after_shop_loop.
     *
     * @hooked woocommerce_pagination - 10
     */
    do_action( 'woocommerce_after_shop_loop' );
} else {
    /**
     * Hook: woocommerce_no_products_found.
     *
     * @hooked wc_no_products_found - 10
     */
    do_action( 'woocommerce_no_products_found' );
}

/**
 * Hook: woocommerce_after_main_content.
 *
 * @hooked woocommerce_output_content_wrapper_end - 10 (outputs closing divs for the content)
 */
do_action( 'woocommerce_after_main_content' );

/**
 * Hook: woocommerce_sidebar.
 *
 * @hooked woocommerce_get_sidebar - 10
 */
do_action( 'woocommerce_sidebar' );

get_footer( 'shop' );
?>

看起来像woocommerce paginations依赖于 woocommerce_product_loopwc_get_loop_prop . 如何强制分页视图使用全局查询?

Note: 我可以确保 woobadge_query_filtered_products 函数生成的 query_posts 正在使用分页参数 .