WP_QUERY分页链接生成404

时间:2013-11-07 作者:user1917727

我已经搜索了数千篇相关帖子,似乎无法在这个循环中使用分页。

只要我点击下一页,我就会得到一个404

//get the search term
if (!empty($_GET["s"])){
$s = $_GET["s"];

//the search form will have an input value of "Search..." if nothing has been selected. We need to clear 
if ($s=="Search..."){
    $s=\'\';
}
}

$paged = (get_query_var(\'paged\')) ? get_query_var(\'paged\') : 1;
$limit = 10;
     $args = array(
    //the user inputed search term
    \'s\' => $s,
    \'post_type\' => \'schools\',   
    \'posts_per_page\' => 5,
    \'paged\' => $paged,
    //we use tax_query here to query the schools custom taxonomy. 
    \'tax_query\' => array(
        \'relation\' => \'AND\',
        array(
            //name of school categories (custom taxonomy)
            \'taxonomy\' => \'school_category\',
            //we are going to search by matching category ids
            \'field\' => \'id\',
            //the array we created that contains all the category ids to be searched
            \'terms\' => $category_and,
            //we want to make sure only posts in all of the categories selected are shown.
            \'operator\' => \'AND\'
        ),
        array(
            //name of school categories (custom taxonomy)
            \'taxonomy\' => \'school_moi\',
            //we are going to search by matching category ids
            \'field\' => \'id\',
            //the array we created that contains all the category ids to be searched
            \'terms\' => $category_MOI,
            //we want to make sure only posts in all of the categories selected are shown.
            \'operator\' => \'AND\'
        ),
        array(
            //name of school categories (custom taxonomy)
            \'taxonomy\' => \'school_curriculum\',
            //we are going to search by matching category ids
            \'field\' => \'id\',
            //the array we created that contains all the category ids to be searched
            \'terms\' => $category_cur,
            //we want to make sure only posts in all of the categories selected are shown.
            \'operator\' => \'AND\'
        )

    )

);

//The new query with our arguements
$wp_query = new WP_Query( $args );

woo_loop_before();

if ($wp_query->have_posts()) { $count = 0;

$title_before = \'<h1 class="archive_header">\';
$title_after = \'</h1>\';

//echo $title_before . sprintf( __( \'Search results for &quot;%s&quot;\', \'woothemes\' ), get_search_query() ) . $title_after;    
    ?>

<div class="fix"></div>

<?php
    //Make sure the search results take into account the categories chosen on the seach bar

    while ($wp_query->have_posts()) {$wp_query->the_post(); $count++;

        if (get_option(\'woo_woo_tumblog_switch\') == \'true\') { $is_tumblog = woo_tumblog_test(); } else { $is_tumblog = false; }

        woo_get_template_part( \'content\', \'search\' );

    } // End WHILE Loop



    next_posts_link(\'&laquo; Next\');
    previous_posts_link(\'Previous &raquo;\');

    //wp_reset_postdata();

  } else {
get_template_part( \'content\', \'noposts\' );
  } // End IF Statement


  woo_loop_after();
我有blog pages show at most option 设置为1。

非常感谢您的帮助!

谢谢

1 个回复
SO网友:adnan

我认为你需要使用wp_reset_query(); 之前woo_loop_after();

结束

相关推荐

Pagination problem

我有两个自定义重写规则:add_rewrite_rule(\'foo/bar/?\', \'index.php?post_type=foo\', \'top\'); add_rewrite_rule(\'foo/bar/([a-z]+)/?\', \'index.php?post_type=foo&bar=$matches[1]\', \'top\'); 这给了我匹配自定义变量的帖子bar. 然而,我也想处理分页,因此当一个数字成功时/bar/ wordpress应将其视为页码。