I’m working on a WordPress site with a custom post type called “Portfolio” and need help with navigation links.
Here’s my setup:
Custom post type: Portfolio
Custom taxonomy: portfolio_categories with URL structure portfolio/category-name
Some categories are parent categories with subcategories
I want to add previous/next navigation links in my single portfolio post template that only cycle through posts in the same category (not all portfolio posts).
Your issue is that previous_post_link() and next_post_link() don’t work with custom taxonomies by default. That TRUE parameter only excludes regular categories, not custom ones.
I ran into this exact problem on a client’s portfolio site last year. Here’s what fixed it:
Switch to get_previous_post() and get_next_post() instead of the link functions, then pass your custom taxonomy as the third parameter. This’ll keep navigation within the same portfolio category.
WordPress’s built-in functions are a pain with custom taxonomies. Had the same issue building a real estate site with property types. Here’s what actually worked:
Create a custom function that manually queries adjacent posts within the same taxonomy term. First, grab your current post’s taxonomy terms. Then use WP_Query to pull posts from that category, ordered by date or menu order. Find your current post’s position in that array and grab the previous/next items.
I also cached the results - running these queries on every page view kills performance. Just make sure you’re filtering by the exact taxonomy slug and handle cases where posts might be in multiple categories.
just use get_adjacent_post() with your taxonomy name. for next: get_adjacent_post(false, '', true, 'portfolio_categories') and for previous set the third param to false. way simpler than custom queries and no caching headaches.