1

Okay. I am not on here often, but I finally gave up trying to debug this myself. I've got a custom post type, with custom taxonomies, and I want a certain number of post thumbnails to show up on a page, and paginate through the others. When clicked on, the URL paginates as it should (showing /page/1/, /page/2/, etc.) however, the same 4 posts show, and will not rotate to the older or newer posts. I've tried different structures, and pagination techniques, but all seems to have failed. Help?

Also--I'm working locally, so it's pretty inconvenient that you can't see the website itself, but I will do my best to provide further information and/or screenshots. Thank you.

<div class="masonryGalleryTheme">
<?php
$args = array(
    'taxonomy' => 'portfolio_categories',
    'term' => 'artwork',
    'post_type' => 'portfolio',
    'posts_per_page' => 4
);
$comments = new WP_Query($args);
if ($comments->have_posts()) : while ($comments->have_posts()) :
        $comments->the_post();
        ?>

        <a href="<?php the_post_thumbnail_url(); ?>" rel="lightbox" title="<?php the_title(); ?> - <?php the_excerpt(); ?>">
            <?php the_post_thumbnail(); ?>
        </a>

    <?php endwhile;
endif;
?>
<?php wp_reset_query(); ?>
</div>

<?php next_posts_link('&laquo; Older Entries', $comments->max_num_pages); ?>
<?php previous_posts_link('&laquo; Newer Entries', $comments->max_num_pages); ?>

I'm sure this will turn out to be a simple solution--and if so, I apologize for my stupidity in advance. XD

1 Answer 1

0

I think you forgot to add this to your query args. By adding this page parameter WP will show the posts that would normally show on page=x.

Solution:

// So that WordPress will know which page to show
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;      

// Our query args array.     
$args = array(
     'taxonomy' => 'portfolio_categories',
     'term' => 'artwork',
     'post_type' => 'portfolio',
     'posts_per_page' => 4,
     'paged' => $paged
);

If this does not work, let me know. :)

3
  • facepalm I did indeed forget this bit. Oops. However, it did not fix my pagination problem. Commented Sep 20, 2016 at 1:39
  • See my edited answer please. Did you try get_query_var('paged') instead of 'page' ? Commented Sep 20, 2016 at 1:39
  • HA! This worked! I've been slaving over this forever! Thank you. Seriously, thank you. Commented Sep 20, 2016 at 1:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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