wordpress - Pagination fails with CPT and dynamic tax_query -


i have search form. choose taxonomy, , select 1 or more terms. want paginate results.

here code:

    <?php          if(isset($_post['tax_type'])) {          $tax_type=$_post['tax_type'];         $terms = $_post[$tax_type];                  $term_list = implode("','", $terms);                 $term_list1 = implode(", ", $terms);                 $term_list = "'".$term_list."'";                   $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;                    $giftfinder_args = array(                 'post_type' => 'products',                  'posts_per_page'=>"1",                 'paged' => $paged,                 'tax_query' => array(                 array(                     'taxonomy' => $tax_type,                     'field'    => 'slug',                     'terms'    => explode(',',$term_list),                     ),                 ),                 );          echo '<div class="results"><span class="eyebrow">search results</span>';                 echo '<div class="cat_label">&#8220;' . $term_list1 . '&#8221;</div></div>';      // query     $giftfinder_query = new wp_query( $giftfinder_args );      // pagination fix         $temp_query = $wp_query;         $wp_query   = null;         $wp_query   = $giftfinder_query; ?>  <?php if ( $giftfinder_query->have_posts() ) : ?>      <!-- loop -->     <?php while ( $giftfinder_query->have_posts() ) : $giftfinder_query->the_post();     $thumb = get_the_post_thumbnail(null, 'medium');     ?>     <div class="prod"><a href="<?php the_permalink(); ?>"><?php if(empty($thumb)) {echo '<div style="width:265px;height:265px;background:#eee;"></div>';} else {the_post_thumbnail('medium');} ?></a><span class="truncate"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></span></div>      <?php endwhile; ?>      <div style="clear:both;"></div>     <!-- end of loop -->      <?php     the_posts_pagination( array(         'prev_text'          => __( 'previous page', 'twentyfifteen' ),         'next_text'          => __( 'next page', 'twentyfifteen' ),         'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( 'page', 'twentyfifteen' ) . ' </span>',     ) );     ?>      <?php wp_reset_postdata(); ?>      <?php else : get_template_part( 'content', 'none' ); endif; ?>     <?php } ?> 

first page fine, no results appear on paginated pages.

as can see, i'm trying use pagination fix turns query $wp_query:

// query $the_query = new wp_query( $args );  // pagination fix     $temp_query = $wp_query;     $wp_query   = null;     $wp_query   = $the_query; 

but said, no results beyond first page.

i going try pre_get_posts can't figure out how code since every query has unique arguments based on user's choice of taxonomy , searched terms.

i tried 'add_args' paginate_links() function not figure out how format resulting string.

btw, right now, query returns 1 post make easy check pagination.

any suggestions appreciated!

not sure if issue, looks have typo.

you setting $page: $page = (get_query_var('paged')) ? get_query_var('paged') : 1;

but looking $paged: 'paged' => $paged,


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -