WordPress.org

Support

Support » How-To and Troubleshooting » Custom post type TAXONOMY prev/next links – by tax/category

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();
    $wp_query->query(array(
    'post_type'=>'products',
    '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;');
    
    the_title();
    the_content();
    endwhile; 
    
    $wp_query = null;
    $wp_query = $temp;  // Reset

    IM SO CLOSE!

Viewing 3 replies - 1 through 3 (of 3 total)
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.
Skip to toolbar