分页不适用于自定义搜索表单和自定义结果模板

时间:2017-04-23 作者:aryan

我使用自定义搜索表单和自定义模板根据中给出的解决方案显示结果here除了分页似乎根本不起作用之外,一切都很好

Overview

自定义帖子类型:job\\u listing自定义分类法:job\\u listing\\u type自定义字段作为关键字:\\u job\\u location这里是搜索表单的代码:

<form method="get" id="advanced-searchform" role="search" action="<?php echo esc_url( home_url( \'/\' ) ); ?>">
    <input type="hidden" name="search" value="advanced">

        <select id="my-select1" class="js-example-basic-single isotopeselect" data-filter-group="proyectos" multiple="multiple" name="terms[]">

        <?php foreach ($job_terms as $job_term): ?>
          <option value=".<?php echo str_replace(\' \', \'-\', str_replace(\'&\', \'and\', html_entity_decode($job_term)));?>"><?php echo $job_term;?></option>
        <?php endforeach; ?>

        </select>    
        <button type="submit"><span>search</span></button>
    <input type="hidden" name="job_listing" value=""/>
</form>
这是搜索结果模板

<?php 
get_header();
$terms=array();
$all=($_REQUEST); 


if(isset($_REQUEST["terms"])){
    $myterms=$all["terms"];
    foreach ($myterms as $myterm) {
    $myterm=str_replace(".","",$myterm);
    $terms[]=$myterm;    
    }
}

if($terms){
    $tax_query[] =  array(
                        array(
                        \'taxonomy\' => \'job_listing_type\',
                        \'field\' => \'name\',
                        \'terms\' => $terms
                      ) );
}

$post_type = \'job_listing\';
$paged= (get_query_var(\'paged\' )) ? get_query_var(\'paged\'):1;
$args         =  array(
    \'paged\'=>$paged,
    \'post_type\'=>$post_type,
    \'posts_per_page\'=>1, 
    \'tax_query\' => $tax_query,
    );
$loop = new WP_Query( $args );     
if($loop->have_posts()):?>

    <div class="my-services">
        <?php    
        while($loop->have_posts()):$loop->the_post();              
        the_title();

        endwhile;
        ?>

    </div>
<?php endif; ?>
    <div class="pagination" id="blog-pagination">
      <span class="previous" ><?php previous_posts_link( \'&larr;Newer\', $loop->max_num_pages  ); ?></span>
      <span class="next"><?php next_posts_link( \'Older &rarr;\', $loop->max_num_pages  ); ?></span>
    </div>
    <?php wp_reset_query();?>     

<?php get_footer(); ?>
初始搜索结果,url如下

http://example.com/?search=advanced&terms%5B%5D=.Eat&job_listing=
在我点击next之后,url变为

http://example.com/page/2/?search=advanced&terms%5B0%5D=.Eat&job_listing

但什么都没发生,结果保持不变

我以前从未这样做过,所以请帮我解决这个问题

1 个回复
SO网友:ClodClod91

我看到了:next_posts_link

使用新wp\\U QUERY()时,必须使用wp\\U reset\\u postdata,并且

<div class="pagination" id="blog-pagination">
  <span class="previous" ><?php previous_posts_link( \'&larr;Newer\', $loop->max_num_pages  ); ?></span>
  <span class="next"><?php next_posts_link( \'Older &rarr;\', $loop->max_num_pages  ); ?></span>
</div>
进入if($loop->have\\u posts()):?>条件

相关推荐

search form redirects to home

Update 案件已结案。我忘了我的函数中有kill函数。php将附件、搜索、作者、每日存档页面重定向到主页。删除了用于搜索的部件,效果良好。很抱歉,感谢您的时间和帮助:)我在wordpress中有一个简单的搜索表单<form role=\"search\" method=\"get\" class=\"search-form\" action=\"<?php echo home_url( \'/\' ); ?>\"> <label> <