Php 为什么我的分页应该只显示1或2页,却显示最大页数?
Search.php 当我的查询搜索了7个只需要显示1页的结果时,为什么分页显示最大页数Php 为什么我的分页应该只显示1或2页,却显示最大页数?,php,html,wordpress,Php,Html,Wordpress,Search.php 当我的查询搜索了7个只需要显示1页的结果时,为什么分页显示最大页数 <?php // $s=$ _GET[ 's']; $catnum=$ _GET[ 'catnum']; $type=$ _GET[ 'type']; $low=$ _GET[ 'low']; $high=$ _GET[ 'high']; $unit_size_x=$ _GET[ 'unit_size_x']; $unit_size_y=$ _GET[ 'unit_si
<?php // $s=$ _GET[ 's']; $catnum=$ _GET[ 'catnum']; $type=$ _GET[ 'type']; $low=$ _GET[ 'low']; $high=$ _GET[ 'high']; $unit_size_x=$ _GET[ 'unit_size_x']; $unit_size_y=$ _GET[ 'unit_size_y']; $post_tag=$ _GET[ 'post_tag']; // if($catnum){ // $taxquerysp[]=a rray( // 'taxonomy'=>'property_categories', // 'include_children'=>false, // 'field'=>'term_id', // 'operator'=>'AND' // ); // } // if($post_tag){ // $taxquerysp[] = array( // 'taxonomy'=>'property_categories', // 'include_children'=>false, // 'field'=>'slug', // 'operator'=>'AND' // ); // } // if($type){ // $metaquerysp[] = array( // 'key'=>'type', // 'value'=> $type, // 'compare'=>'=', // ); // } $metaquerysp[] = array( 'key'=>'monthly_rent', 'value'=>array( $low, $high ), 'compare'=>'BETWEEN', 'type'=>'NUMERIC', ); $metaquerysp[] = array( 'key'=>'unit_size', 'value'=>array( $unit_size_x, $unit_size_y ), 'compare'=>'BETWEEN', 'type'=>'NUMERIC', ); $metaquerysp['relation'] = 'AND'; ?>
<?php $paged=g et_query_var( 'paged') ? get_query_var( 'paged') : 1; $args=a rray( 'post_type'=> 'property', 'posts_per_page' => 9, 'orderby' => 'DATE', 'paged' => $paged, // 's' =>$s // 'tax_query' => $taxquerysp, 'meta_query' => $metaquerysp ); ?>
<?php $query=n ew WP_Query( $args ); ?>
<div class="mtb30" style=" display: block;">
<?php if($query -> have_posts()): ?>
<?php while($query -> have_posts()): $query->the_post();?>
<p>
<?php the_excerpt(); ?>
</p>
</div>
</div>
<?php endwhile; ?>
<?php else: ?>
<?php endif; ?>
</div>
<?php wp_reset_postdata();?>
</div>
</div>
<?php if (function_exists( "pagination")) { pagination($wp_query->max_num_pages); } ?>
这是我的作品的url您将过滤结果存储在变量$query中,但稍后,对于分页,您将使用$wp_query 如果您更改以下内容,它应该可以工作:
pagination($wp_query->max_num_pages);
到
这将为您实际进行的查询提供最大页数。将所有相关代码以文本而不是图像的形式粘贴到您的问题中。对不起,我是新来的,我已经编辑过了,谢谢。您正在定义并使用$query,但您正在将$wp\u query->max\u num页面发送到分页。你不应该发送$query->max\u num\u页面吗?这就解决了问题,我怎么会错过这个。谢谢@MagnusErikssonI,我把它作为一个答案写了出来,所以你可以接受它。
pagination($query->max_num_pages);