我创建了一个带有自定义查询的循环。这个查询包含一个php参数,我使用GET方法从url获取该参数。问题是分页(即使它在第一页计算正确的帖子数)工作不正常。我在第二页看到404错误。这是我的循环页面上的代码:
$cat = get_queried_object();
echo \'<h1 class="childcatdes">\'. $cat->name . \'</h1>\';
echo \'<p class="childcatdescr">\'. $cat->description . \'<br><br></p>\';
do_action( \'woocommerce_before_single_product\' );
$posts_per_page = 12;
$paged = ( get_query_var(\'paged\') ) ? get_query_var(\'paged\') : 1;
$product_args = array(
\'post_type\' => \'product\',
\'posts_per_page\' => $posts_per_page,
\'paged\' => $paged,
\'page\' => $paged,
\'tax_query\' => array(
\'relation\' => \'AND\',
array(
\'taxonomy\' => \'product_cat\',
\'field\' => \'name\',
\'terms\' => $cat->name,
),
array(
\'taxonomy\' => \'manufacturers\',
\'field\' => \'slug\',
\'terms\' => $_GET[\'filter_manufacturers\'],
\'operator\' => \'IN\'
)
),
\'orderby\' => \'name\',
\'order\' => \'ASC\',
);
$custom_query = new WP_Query( $product_args );
if($custom_query->have_posts()) {
echo \'<ul\';
while ($custom_query->have_posts() ) : $custom_query->the_post();
echo \'<li>\';
$link = get_the_permalink();
echo \'<a href="\' . $link . \'">\' . get_the_title() . \'</a>\';
echo \'</li>\';
endwhile;
echo \'</ul>\';
}
else {
echo \'No post found.\';
}
?>
<nav class="pagination">
<?php pagination_bar( $custom_query); ?>
</nav>
我用这个代码来实现我的函数。函数pagination\\u bar的php文件
function pagination_bar( $custom_query) {
$total_pages = $custom_query->max_num_pages;
$big = 99999;
if ($total_pages > 1){
$current_page = max(1, get_query_var(\'paged\'));
echo paginate_links(array(
\'base\' => preg_replace(\'/\\?.*/\', \'/\', get_pagenum_link(1)) . \'%_%\',
\'current\' => $current_page,
\'format\' => \'page/%#%/\',
\'total\' => $custom_query->max_num_pages,
\'add_args\' => array(
\'filter_manufacturers\' => $_GET[\'filter_manufacturers\'],
)
));
}
}
当我在product\\u args中不使用分类制造商时,所有这些都正常工作。
请给出建议