我正在使用自定义查询对自定义分类法进行高级搜索。不使用“tax\\u query”时,我的分页工作正常。当我使用“tax\\u query”时,它不会显示任何到下一页的帖子,只会显示我的“未找到”通知。我的代码在这里
/*
Template Name: search result
*/
?>
<!-- prerequisite for search result show -->
<?php
// create array of all category list with empty
$all_cat=array();
$args = array(
\'hide_empty\' => true,
);
$custom_terms = get_terms(\'ad_category\',$args);
foreach($custom_terms as $key) {
$all_cat[]=$key->slug;
}
// end of foreach loop
// end of taking all the arry of category list
// create array of all location list with empty
$all_location=array();
$args = array(
\'hide_empty\' => true,
);
$custom_terms = get_terms(\'locations\',$args);
foreach($custom_terms as $key) {
$all_location[]=$key->slug;
}
// end of foreach loop
// end of taking all the arry of category list
$get_location= $_POST[\'loc\']; // get the selected value for location
$v1=array();
$get_category=$_POST[\'cat\']; // get the selected value for category
// code for checking where any category select or not
if($get_category=="C") // if no category selected then it return "C" as defauolt value
{
// if defalut value then we need all the category in our search result
}
else
{
$all_cat=array( $get_category); // if any category selected then just use this as search
}
// code for checking where any location select or not
if($get_location=="L") // if no location selected then it return "L" as defauolt value
{
// default value means all location
}
else
{
$all_location=array( $get_location); // if any category selected then just use this as search
}
wp_reset_query(); // reset wprdpress query
?>
<!-- prerequisite for search result show -->
<?php get_header(); ?>
<section class="container bodychild"> <!--container-->
<?php
$sidebar_data = array(
\'umenu\' => 1,
\'heading\'=> \'Tack\',
\'updata\'=> \'för att du bidrar till en bättre värld!\',
\'downdata\'=> \'Läs mer om Busenkelt.nu Klicka här\',
);
include (\'sidebar.php\');
?>
<section class="content_area">
<div class="heap">
<h1>Testing Pagination</h1>
<div class="ask-img">
<img src="<?php echo get_template_directory_uri(); ?>/images/icon-info.png">
</div>
<img class="rimg" src="<?php echo get_template_directory_uri(); ?>/images/icon/icon-heart.png">
</div>
<hr class="uhr">
<?php
if ( is_user_logged_in() ){
?>
<div class="ad-con">
<?php
global $current_user;
get_currentuserinfo();
?>
<?php $p = (get_query_var(\'paged\')) ? get_query_var(\'paged\') : 1; ?>
<?php
global $query_string;
$args = wp_parse_args($query_string);
$post_pre_page=5;
$offset = ( $p - 1 ) * $post_pre_page;
$args = array( \'post_type\' => \'advertise\',
\'post_status\' => \'publish\',
\'posts_per_page\' => $post_pre_page,
// \'tax_query\' => array(
// array(
// \'taxonomy\' => \'ad_category\',
// \'field\' => \'slug\',
// \'terms\' => $all_cat,
// \'operator\' => \'IN\'
// )
// ),
\'offset\'=> $offset,
\'orderby\'=>\'date\',
\'order\'=>\'DESC\',
\'paged\'=>$p,
);
$loop = new WP_Query($args);
query_posts($args);
global $wp_query;
// Store it for safekeeping
$temp_wp_query = $wp_query;
// Now blank it out
$wp_query = null;
// Now populate it with your custom query
$wp_query = $loop;
?>
<div class="prevnext">
<p>
<span class="left">
<?php echo \'Page \'. $p . \' of \' .$loop-> max_num_pages; ?>
</span>
</p>
</div>
<hr class="uhr">
<?php if ( have_posts() ) {?>
<?php while ( have_posts() ) : the_post(); ?>
<div class="ind-ad" id="<?php echo \'ad-\'.get_the_ID();?>">
<div class="show-ads-con">
<div class="show-ads-sub1">
<div class="show-ads1">
<?php if ( get_post_meta( get_the_ID(), \'add_image1\', true ) ) { ?>
<?php $imager = get_post_meta( get_the_ID(), \'add_image1\', true ) ;?>
<img class="thumb" src="<?php echo wp_get_attachment_url($imager); ?>" alt="<?php the_title(); ?>" />
<?php }
else {
echo "no image 1";
}
?>
</div>
</div>
<div class="show-ads-sub2">
<div class="show-ads2">
<?php if ( get_post_meta( get_the_ID(), \'add_image2\', true ) ) { ?>
<?php $imager = get_post_meta( get_the_ID(), \'add_image2\', true ) ;?>
<img class="thumb" src="<?php echo wp_get_attachment_url($imager); ?>" alt="<?php the_title(); ?>" />
<?php }
else {
echo "no image 2";
}
?>
</div>
<div class="show-ads3">
<?php if ( get_post_meta( get_the_ID(), \'add_image3\', true ) ) { ?>
<?php $imager = get_post_meta( get_the_ID(), \'add_image3\', true ) ;?>
<img class="thumb" src="<?php echo wp_get_attachment_url($imager); ?>" alt="<?php the_title(); ?>" />
<?php }
else {
echo "no image 3";
}
?>
</div>
<div class="show-ads4">
<?php if ( get_post_meta( get_the_ID(), \'add_image4\', true ) ) { ?>
<?php $imager = get_post_meta( get_the_ID(), \'add_image4\', true ) ;?>
<img class="thumb" src="<?php echo wp_get_attachment_url($imager); ?>" alt="<?php the_title(); ?>" />
<?php }
else {
echo "no image 4";
}
?>
</div>
</div>
</div>
<div class="man-ad-info">
<h3> Post id : <?php the_ID(); ?></h3>
<h3> Title : <?php the_title() ?></h3>
<h3> Author Name : <?php the_author(); ?> </h3>
<h3> Author Id : <?php the_author_meta(\'ID\')?> </h3>
<p> Gilltig till: </p>
<div class="bllab">
<label>
<select>
<option>
<?php if ( get_post_meta( get_the_ID(), \'val-year\', true ) ) { ?>
<?php echo get_post_meta( get_the_ID(), \'val-year\', true ) ; ?>
<?php }
else {
echo "no data";
}
?>
</option>
</select>
</label>
<label>
<select>
<option>
<?php if ( get_post_meta( get_the_ID(), \'val-month\', true ) ) { ?>
<?php echo get_post_meta( get_the_ID(), \'val-month\', true ) ; ?>
<?php }
else {
echo "no data";
}
?>
</option>
</select>
</label>
<label>
<select>
<option>
<?php if ( get_post_meta( get_the_ID(), \'val-day\', true ) ) { ?>
<?php echo get_post_meta( get_the_ID(), \'val-day\', true ) ; ?>
<?php }
else {
echo "no data";
}
?>
</option>
</select>
</label>
</div>
<p class="man-status"> Status: </p>
<div class="btn-container">
<div class="btn-on-left">
<a href="#">
<div class="btn-left-a clico"></div>
<div class="btn-right-a"> Ta bort</div>
</a>
</div>
</div>
</div>
<hr class="uhr">
</div>
<?php endwhile; ?>
<div class="pagination">
<?php
// $big = 999999999; // need an unlikely integer
// echo paginate_links( array(
// \'base\' => str_replace( $big, \'%#%\', get_pagenum_link( $big ) ),
// \'format\' => \'?paged=%#%\',
// \'current\' => max( 1, get_query_var(\'paged\') ),
// \'total\' => $loop->max_num_pages,
// \'prev_text\' => __(\'« Previous\'),
// \'next_text\' => __(\'Next »\')
// ));
?>
<ul class="pagination">
<li id="previous-posts">
<?php previous_posts_link( \'<< Previous Posts\', $loop->max_num_pages ); ?>
</li>
<li id="next-posts">
<?php next_posts_link( \'Next Posts >>\', $loop->max_num_pages ); ?>
</li>
</ul>
</div>
<?php
}
else {
echo \'<div class="user-nli"> no sparade ad found for this author. </div>\';
echo \'<hr class="uhr">\';
}
wp_reset_postdata();
$wp_query = $temp_wp_query;
?>
</div>
<?php
}
else {
echo \'<div class="user-nli"> If registered User? go to <a href="\'.get_site_url().\'"> Home page </a> and Log in Or <a href="\'.esc_url( get_permalink( get_page_by_title( \'Registrering\' ) ,false)).\'">Register</a> as a User. </div>\';
echo \'<hr class="uhr">\';
}
?>
<div class="content_button_left">
<a href="<?php echo home_url(); ?>">
<input class="gostep1" type="button" value="Next Stage">
</a>
</div>
</section>
<div class="clear"></div>
</section><!-- end container -->
<?php require_once(\'check.php\');?>
<?php get_footer(); ?>