php - Custom Post Pagination Not Working -


i know there have been many pagination questions, i'm stumped here. have "gallery" hierarchical custom post type. parent posts, i'm using index template, , child posts uses more typical single page code.

here's of single-gallery.php file. check see if post has children. if does, want index page.

get_header();  $template = get_template_directory_uri();  //if it's index page, redirect $args = array(     'post_parent' => $post->id,     'post_type'   => 'gallery',      'numberposts' => -1,     'post_status' => 'publish'  ); $children = get_children( $args );  if ($children){     get_template_part('template-parts/content', 'gallery-index');     get_footer(); } else{ 

after else, outputs code single display, working fine.

in content-gallery-index.php, have.

$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1; 

then goes on handle code another, unrelated page. lower in template, have following (i included of request):

<?php elseif (is_page(343) || $post_type == 'gallery' ):      $post_parent = 343;     $type = 'page';     if ($post_type == 'gallery'){         $post_parent = $post->id;         $type = 'gallery';     }     $args = array(         'post_type' => $type,         'post_parent' => $post_parent,         'posts_per_page' => 6,         'paged' => $paged,     );     $query = new wp_query($args);     if ($query->have_posts()): ?>         <div class="box-steps">             <?php while($query->have_posts()): $query->the_post();                  $image = get_the_post_thumbnail();                 $permalink = get_the_permalink();                 if (!get_field('dont_include_in_services')): ?>                      <section class="box-step">                         <div class="box-step-img-wrapper">                             <a href="<?php echo $permalink; ?>">                                 <?php the_post_thumbnail(); ?>                             </a>                         </div>                         <div class="box-step-content-wrapper">                             <h2 class="box-step-title our-services-title header-font"><?php echo get_the_title(); ?></h2>                             <?php if ($post_type == 'gallery'): ?>                                 <p class="box-step-content"><?php echo get_the_content($post->id); ?></p>                             <?php else: ?>                                 <p class="box-step-content"><?php echo esc_html(get_field('preview_text')); ?></p>                                 <a class="box-step-link block bold" href="<?php echo $permalink; ?>">                                     read more                                 </a>                             <?php endif; ?>                         </div>                     </section>                  <?php endif; ?>              <?php endwhile; ?>         </div>       <?php endif; wp_reset_postdata(); ?>     <!-- pagination here -->     <?php         custom_pagination($query->max_num_pages,"",$paged);     ?>  <?php endif; ?> 

functions.php

function custom_pagination($numpages = '', $pagerange = '', $paged='') {  if (empty($pagerange)) {     $pagerange = 2; }  global $paged; if (empty($paged)) {     $paged = 1; } if ($numpages == '') {     global $wp_query;     $numpages = $wp_query->max_num_pages;     if(!$numpages) {         $numpages = 1;     } }  $prev_arrow = is_rtl() ? '&raquo;' : '&laquo;'; $next_arrow = is_rtl() ? '&laquo;' : '&raquo;';  $pagination_args = array(     'base'            => get_pagenum_link(1) . '%_%',     'format'          => 'page/%#%',     'total'           => $numpages,     'current'         => $paged,     'show_all'        => false,     'end_size'        => 1,     'mid_size'        => $pagerange,     'prev_next'       => true,     'prev_text'       => __('&laquo;'),     'next_text'       => __('&raquo;'),     'type'            => 'list',     'add_args'        => false,     'add_fragment'    => '',     'prev_text'     => $prev_arrow,     'next_text'     => $next_arrow, );   $paginate_links = paginate_links($pagination_args);  if ($paginate_links) {     echo "<nav class='custom-pagination'>";     //echo "<span class='page-numbers page-num'>page " . $paged . " of " . $numpages . "</span> ";     echo $paginate_links;     echo "</nav>"; } 

}

the strange thing numbered pagination output fine, when click on page two, it's url gets rewritten , page refreshes. same code has worked on page, page not custom post type. i've tried trick of turning wp_query null , resetting it, other errors.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -