我有一个wordpress页面,上面有一系列列表和一个搜索框。搜索允许用户通过根据所选内容创建自定义WP\\U查询对象来筛选帖子。我想知道是否有一种方法可以将其分页,这样页面上就不会显示数百个结果。
基本上,我有一个if语句来检查表单是否已提交,然后将所选字段填充到一个数组中,并将其传递给meta\\u查询
$paged = (get_query_var(\'paged\')) ? get_query_var(\'paged\') : 1;
if(isset($_POST[\'submit\'])){
$the_query = new WP_Query(array(
\'post_type\' => \'business\',
\'post_status\' => \'publish\',
\'taxonomy\' => \'business-type\',
\'business-type\' => \'attraction\',
\'posts_per_page\' => 15,
\'orderby\' => \'title\',
\'order\' => \'ASC\',
\'meta_query\' => $arrays,
\'paged\' => $paged
));
}else{
$the_query = new WP_Query(array(
\'post_type\' => \'business\',
\'post_status\' => \'publish\',
\'taxonomy\' => \'business-type\',
\'business-type\' => \'attraction\',
\'posts_per_page\' => 15,
\'orderby\' => \'title\',
\'order\' => \'ASC\',
\'paged\' => $paged
));
我使用
while ( $the_query->have_posts() ) : $the_query->the_post();
结束后;我有我的页码
if($the_query->max_num_pages>1){?>
<div class="pagination">
<?php
if ($paged > 1) { ?>
<a href="<?php echo \'?paged=\' . ($paged -1); //prev link ?>"><</a>
<?php }
for($i=1;$i<=$the_query->max_num_pages;$i++){
if($paged==$i){?>
<span class="current"><?php echo $i; ?></span>
<?php }else{?>
<a href="<?php echo \'?paged=\' . $i; ?>" class="inactive"><?php echo $i;?></a>
<?php
}
}
if($paged < $the_query->max_num_pages){?>
<a href="<?php echo \'?paged=\' . ($paged + 1); //next link ?>">></a>
<?php } ?>
</div>