0

I'm working with a custom post type / custom taxonomy combo and I can't seem to get pagination to work properly. I'm wanting to add an infinite scroll to the page, however I can't even get pagination to even show up in order to get the infinite scroll piece working.

Below is my loop:

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

        $args = array(
            'post_type' => 'shows', // it's default, you can skip it
            'posts_per_page' => '3',
            'order_by' => 'date', // it's also default
    'paged' => $paged,
    'tax_query' => array(
                array(
                        'taxonomy' => 'show',
                        'field' => 'slug',
                        'terms' => array( 
                            'anger-management' 
                        )
                )
            )  
            );
            $query = new WP_Query( $args );
    ?>
        <?php if (have_posts()) : while( $query->have_posts() ) : $query->the_post(); ?>

            <div class="archive-item" style="background: url(<?php echo get('archive_image'); ?>) center center no-repeat;"><a href="<?php the_permalink(); ?>">

                <div class="archive-item-content">

                    <h3><?php the_title(); ?></h3>
                    <p><?php echo get('location'); ?>  -  <?php echo get('date'); ?></p>

                </div></a>

            </div>

    <?php endwhile; ?>



    <?php endif; ?>

    <?php wp_reset_query(); ?>

Obviously, I've put in a pagination script after the endwhile, however it still does not work; I've even tried a plugin just to see if it'd work, and it didn't.

I'm using the HTML5blank theme to build from, so here's the pagination script that comes built in:

function html5wp_pagination()
{
    global $wp_query;
    $big = 999999999;
    echo paginate_links(array(
        'base' => str_replace($big, '%#%', get_pagenum_link($big)),
        'format' => '?paged=%#%',
        'current' => max(1, get_query_var('paged')),
        'total' => $wp_query->max_num_pages
    ));
}

I'm not sure if I need to write a new one or not; to be honest, I'd prefer just to have basic "next posts" or "previous posts" links, but regardless, I just can't get the pagination to work AT ALL.

Any help would be much appreciated.

I guess I'm starting to wonder if I need to set some parameters for this type of loop that helps set up the pagination? But I can't seem to figure that out if that's the case.

2 Answers2

0

Your function html5wp_pagination() is using global $wp_query;

But you're using $query = new WP_Query( $args );

Try changing that to $wp_query = new WP_Query( $args ); And adjust the while line so that it uses $wp_query.

shanebp
  • 5,095
  • 7
  • 28
  • 40
0

You can do what @shanebp said, but you can even do a little more and follow @Chip Bennett's "guide" on how to fix pagination for custom loops

Marcos Rodrigues
  • 481
  • 4
  • 10