Support » Fixing WordPress » Custom post type TAXONOMY prev/next links – by tax/category

  • I have created a custom post type (products) with dynamic category taxonomies that the client sets up in wordpress.
    Im trying to ‘drill down’ like this:

    all categories (home.php) > all products in category (taxonomy.php) > single (single-products.php)

    and when you get to a single product, I set it up to cycle through all products in the current category.

    Its all working, except when you click the prev or next post_link, it just clicks through all categories, in order each product was published.

    Is there a way to contain the pagination to the current taxonomy, and start/stop at the end of the posts in that category?

    heres my code:

    $temp = $wp_query;
    $wp_query = null;
    $wp_query = new WP_Query();
    'taxonomy'=> 'product_categories',
    'paged' => $paged,
    'posts_per_page' => 1,
    while ($wp_query->have_posts()) : $wp_query->the_post();
    the_post_thumbnail( 'single' );
    previous_posts_link('« Previous');
    $terms = wp_get_post_terms( $post->ID, 'product_categories');
    	foreach ($terms as $term) {
    	echo '<a href="'.get_term_link($term->slug, 'product_categories').'">'.$term->name.'</a>';
    next_posts_link('Next &raquo;');
    $wp_query = null;
    $wp_query = $temp;  // Reset


Viewing 3 replies - 1 through 3 (of 3 total)
  • If this code of single.php there is next_post_link instead of next_posts_link(). The last one is for index page and archives navigation.
    next_post_link() has parameter in_same_cat.

    In addition there is some plugins for advanced next/prev navigation:
    Ambrosite Next/Previous Post Link Plus
    Previous and Next Post in Same Taxonomy

    Hi digitalrenewal, you might want to have a look at this. Had run into the same issue previously and thought I might take a note of it:

    And by the way, will be useful to take note of vjpo’s comment – the difference between next_post_link and next_posts_link. Though it doesn’t actually solve your custom tax issue.



    Smarter Navigation – another good one plugin. Based on browser cookies.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Custom post type TAXONOMY prev/next links – by tax/category’ is closed to new replies.