I have 4 categories for my custom post type. Once I go the first post of Category 1, I’d like this pagination, to only loop me through the posts within Category 1.

I followed this article to create my pagination, but it only works if I enter the name of one of my taxonomy terms – and then it only works for that category (ie. Theatre)

My Custom Post Type is called “works” and my custom taxonomy is called “work”.

Here’s my code so far:

<?php // get_posts in same custom taxonomy
$postlist_args = array(
'posts_per_page'  => -1,
'orderby'         => 'menu_order title',
'order'           => 'ASC',
'post_type'       => 'works',
'work' => 'theatre'
$postlist = get_posts( $postlist_args );

// get ids of posts retrieved from get_posts
$ids = array();
foreach ($postlist as $thepost) {
$ids[] = $thepost->ID;

// get and echo previous and next post in the same taxonomy        
$thisindex = array_search($post->ID, $ids);
$previd = $ids[$thisindex-1];
$nextid = $ids[$thisindex+1];
if ( !empty($previd) ) {
echo '<a class="button-icon" rel="prev" href="' . get_permalink($previd). '">Previous</a>';
if ( !empty($nextid) ) {
echo '<a class="button-icon" rel="next" href="' . get_permalink($nextid). '">Next</a>';
} ?>

Is there another way to do this, that will only loop me through the posts within that category?

Read more here: Pagination Custom Post Type with Custom Category/Taxonomy


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Wordpress related questions and answers: