0

I have a custom taxonomy that is pulling in a list of posts assosciated with it. Previously - in the $posts_args array, I set the post_per_page option to -1 but realized pagination should be added to do the large amount of media that will be present with each post. I read over paginate_links() (and added their example in my query below), but have not had any luck thus-far parsing out the posts as needed. Right now - posts_per_page is set to 2 in the general WordPress > Reading settings (which works - only 2 posts are shown on the page) and the paginate_links() function call does in-fact generate the amount of pages needed based on the posts per page and the total number of posts, but when I do go to the secondary pages (like /page/2) the same posts are shown that are on the first page. Any suggestions on what I may be missing? Thanks!

$post_args = array(
    'post_type' => 'moulding_profiles',
    'meta_key' => '_mouldings_dimensions_height',
    'orderby' => 'meta_value_num',
    'order' => 'ASC',
    'tax_query' => array(
            array(
                'taxonomy' => $taxfunc_tax_name,
                'field' => 'id',
                'include_children' => 0,
                'terms' => $term_id
            )
        )
);
$posts_query = new WP_Query($post_args);
$i = 0; // count
$total_items = $posts_query->post_count; // total profiles
$number_columns = $mouldings_options['profile_item_columns']; // number of columns
if ($posts_query->have_posts() ) {

    // Filter function
    mouldings_profile_list_before();

    echo '<div id="mouldings-list">';
    while($posts_query->have_posts() && ($i < $total_items)) { ?>
        <?php $posts_query->the_post(); if ($i % $number_columns == 0) echo ($i > 0 ? '</div><div class="row">' : '<div class="row first-row">'); ?>
        <div class="<?php echo 'width'.intval(100 / $number_columns); ?> <?php if ($i % $number_columns == 0) echo 'first-item'; ?>">
            <?php
                moulding_profile_teaser($profile_ID = get_the_ID());
            ?>
        </div>
    <?php $i++;
    }
    echo '</div>';
    echo '</div>';

    mouldings_profile_list_after();

    $big = 999999999; // need an unlikely integer
    echo paginate_links( array(
        'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
        'format' => '?paged=%#%',
        'current' => max( 1, get_query_var('paged') ),
        'total' => $posts_query->max_num_pages
    ) );
}
wp_reset_query();
0

Looks like I was missing 'paged' => get_query_var('paged') in the initial query.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.