我正在尝试使用wp\\u查询创建自定义搜索页面。我正在使用post方法获取搜索值。起初,搜索做得很好,但当我得到超过4篇文章的搜索结果(我设置每页显示4篇文章)并尝试访问结果的第二页时,它会返回到正常的查询结果(没有搜索值)。这是我的代码:
if (isset($_POST[\'btn_search\'])) {
$by_year = $_POST[\'sel_year\'];
$by_platform = $_POST[\'sel_platform\'];
$by_title = $_POST[\'txt_title\'];
$by_genre = $_POST[\'txt_genre\'];
if ($by_year!=""&&$by_platform!="") {
$by_year = $by_year."+".$by_platform;
}
}
我将平台和年份字段组合在一起,因为它们都在类别中。这里是查询:$currentPage = get_query_var(\'paged\');
$allGames = new WP_Query(array(
\'category_name\' => $by_year,
\'posts_per_page\' => 4,
\'tag\' => $by_genre,
\'paged\' => $currentPage,
\'s\' => $by_title
));
if ($allGames->have_posts()) {
while ($allGames->have_posts()) {
$row_counter++;
$post_count++;
$row_start = "";
$row_end = "";
$allGames->the_post();
if ($row_counter!=2) {
$row_start = \'<div class="row"><div class="card-deck">\';
} else {
$row_end=\'</div></div><br>\';
$row_counter=0;
}
if ($post_count==$allGames->post_count) {
$row_end=\'</div></div><br>\';
$row_counter=0;
$post_count=0;
}
echo $row_start;
echo \'<div class="col-md-6 col-sm-12 text-center">
<!-- Card -->
<div class="card special-color">
<!-- Card image -->
<div class="view overlay zoom">
<img class="card-img-top" src="\'.get_the_post_thumbnail_url().\'" alt="Card image cap">
<a href="#!">
<div class="mask rgba-white-slight"></div>
</a>
</div>
<!-- Card content -->
<div class="card-body">
<!-- Title -->
<h2 class="card-title"><a class="text-white-50" href="\'.get_the_permalink().\'">\'.get_the_title().\'</a></h2>
<!-- Text -->
<p class="card-text">\'.get_the_excerpt().\'</p>
<!-- Button -->
<a href="#" class="btn blue-grey btn-block">View</a>
</div>
</div>
<!-- Card -->
</div>\';
echo $row_end;
}
}
?>
<div class="text-center">
<?php
echo paginate_links(array(
\'total\' => $allGames->max_num_pages
));
wp_reset_postdata();
?>
</div>
我希望尽快得到答复。我非常需要:(。提前谢谢!