我必须在侧边栏中搜索各种表单。这两种表格都在中处理search.php
按if/else语句分页,并为两者编写自定义查询。我还将默认wordpress查询替换为我的查询,以便the_posts_pagination
工作正常。对于我的第一个搜索查询,它工作得很好,并且显示了正确的数字,但是在我的第二个查询中,它显示了正确的页码,但是当我单击数字时,404页!下面是我的一段代码:
$paged = ( get_query_var( \'paged\' ) ) ? get_query_var( \'paged\' ) : 1;
if(fist form is filled) {
$adSearchQuery = new WP_Query(array(
\'post_type\' => \'post\',
\'category__in\' => array(1,3,4),
\'posts_per_page\' => 3,
\'paged\' => $paged
));
$temp_query = $wp_query;
$wp_query = NULL;
$wp_query = $adSearchQuery;
// Show posts
the_posts_pagination();
$wp_query = NULL;
$wp_query = $temp_query;
wp_reset_postdata();
}
else {
$tax_query = array(
array(
\'taxonomy\' => \'health\',
\'field\' => \'term_id\',
\'terms\' => "126"
)
);
$aposts = new WP_Query(array(
\'type\' => \'post\',
\'category_name\' => "test",
\'tax_query\' => $tax_query,
\'posts_per_page\' => 3,
\'paged\' => $paged
));
$temp_query = $wp_query;
$wp_query = NULL;
$wp_query = $aposts;
// Show posts
the_posts_pagination();
$wp_query = NULL;
$wp_query = $temp_query;
wp_reset_postdata()
}
但我不知道为什么第二个分页不起作用,尽管它有正确的总帖子数和页码。