Support » Fixing WordPress » Second loop based on current single page custom categories

  • Hi guys,

    I have a products page with two custom taxonomies (symptoms and age_group). I then have a custom post type Symptoms which shares the very same taxonomy (symptoms).

    In both instance I would check the symptoms for the product and the symptoms (fever for example will only be assigned to one taxonomy which will be fever). The product can be assigned to various symptoms and the symptoms only to one.

    What I have at the moment is the the loop runs normally to list the products based on the (age group) taxonomy and click through to a single product page. On the single page, I want to be able to run a second loop that will check the single page’s custom (symptoms) taxonomy and get those categories for use when querying the symptoms.

    This is my loop, however it returns everything it finds.

    <?php
    	$terms = get_the_terms( $post->ID, 'symptoms_cat' );
    	if($terms){
    		foreach ($terms as $term){
    			$x = $term->term_id;
    			//$x = $terms->name;
    		}
    	}
    ?>
    
    	<!-- Execute loop -->
    	<?php
    		query_posts(
    			array(
    				'post_type' => 'symptom',
    				///'category_name' => $x,
    				'category_name' => $term,
    				'posts_per_page' => 99
    			)
    		);
    	?>

  • The topic ‘Second loop based on current single page custom categories’ is closed to new replies.