我正在查询多个分类法,对此没有问题,但分页无法解决它,我尝试了很多建议,但都没有成功。这是我的代码
if ( get_query_var(\'paged\') ) {
$paged = get_query_var(\'paged\');
} elseif ( get_query_var(\'page\') ) {
$paged = get_query_var(\'page\');
} else {
$paged = 1;
}
if(isset($_POST[\'genre\'])) {
$myquery[\'tax_query\'] = array(
\'showposts\' => 20 ,
\'orderby\' => \'title\',
\'order\' => \'ASC\',
\'paged\' => $paged,
\'relation\' => \'AND\',
array(
\'taxonomy\' => \'anime_genre\',
\'terms\' => $_POST[\'genre\'],
\'field\' => \'slug\',
\'operator\' =>\'AND\'
)
);
}
query_posts($myquery);
if (have_posts()):
while (have_posts()):
the_post();
mystique_post();
endwhile;
wp_pagenavi();
else: ?>
<h1 class="title error"><?php _e("No posts found","mystique"); ?></h1>
<p><?php _e("Sorry, but you are looking for something that isn\'t here.","mystique"); ?></p>
<?php
endif;
我对查询分类法没有问题,但只有分页不起作用
最合适的回答,由SO网友:user1489083 整理而成
我设法解决了自己的问题,但又出现了另一个问题,
$paged = 1;
if ( get_query_var(\'paged\') ) $paged = get_query_var(\'paged\');
if ( get_query_var(\'page\') ) $paged = get_query_var(\'page\');
$args=array(
\'paged\' => $paged,
\'post_type\'=>\'animes\',
\'post_status\'=>\'publish\',
\'order\'=>\'ASC\',
\'posts_per_page\'=>\'15\',
\'orderby\'=>\'title\',
\'tax_query\'=>array(
array(
\'taxonomy\' => \'anime_genre\',
\'terms\' => array(\'drama\',\'romance\'),
\'field\' => \'slug\',
\'operator\' =>\'AND\',
),
)
);
print_r($args);
$loop = new WP_Query($args);
//wp_reset_postdata();
//query_posts($myquery);
if ($loop->have_posts()){
//while ( have_posts() ) : the_post();
while ( $loop->have_posts() ) : $loop->the_post();
// output
// the_post();
$loop->the_post();
mystique_post();
endwhile;
//mystique_pagenavi();
if ( function_exists( \'wp_pagenavi\' ) ) {
wp_pagenavi( array( \'query\' => $loop ) );
wp_reset_postdata();
}
}
SO网友:Reza Mamun
这可能有助于:
........
........
if(isset($_POST[\'genre\'])) {
$myquery = array(
\'showposts\' => 20 ,
\'orderby\' => \'title\',
\'order\' => \'ASC\',
\'paged\' => $paged,
\'tax_query\' => array(
\'relation\' => \'AND\',
array(
\'taxonomy\' => \'anime_genre\',
\'terms\' => $_POST[\'genre\'],
\'field\' => \'slug\',
\'operator\' =>\'AND\'
)
)
);
}
query_posts($myquery);
......