• I have some code for displaying a taxonomy “wood_type” but nothing is showing up with the code that I have here. Any ideas?

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    
    <?php
    
    get_template_part( 'content' );
    
    //for a given post type, return all
    $post_type = 'molding_profile';
    $tax = 'wood_type';
    $taxonomy_term_id = $wp_query->queried_object_id;
    $tax_terms = get_terms($tax, 'slug='.$queried_term);
    if ($tax_terms) {
      foreach ($tax_terms as $tax_term) {
        $args=array(
          'post_type' => $post_type,
          "$tax" => $tax_term->slug,
          'post_status' => 'publish',
          'posts_per_page' => -1,
        );
    
        $my_query = null;
        $my_query = new WP_Query($args);
        if( $my_query->have_posts() ) {
    
          while ($my_query->have_posts()) : $my_query->the_post(); ?>
    
          		<div style="padding-left:0;" class="four columns left for-mobile">
          			<div style="text-align:center;" class="twelve columns mp-img">
          				<a href="<?php the_permalink(); ?>">
          					<img src="<?php the_field('profile_thumb_image'); ?>" />
          				</a>
          			</div>
          		<div style="text-align:center; margin-bottom:30px;">
    	      		<span style="margin-right:12px; color:#3F7091;"><?php the_title(); ?></span>
    	      		<span style="color:#A97147"><?php the_field('profile_dimensions'); ?></span>
    	      	</div>
    	      </div>
    
            <?php
          endwhile;
        }
        wp_reset_query();
      }
    }
    ?>
    
    <?php endwhile; endif; ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • Try debugging. F.e. do a print_r on $tax_term or try a testrun with manually added terms, like ‘oak’? instead of $tax_term->slug. That should give some insight to the problem.

    Thread Starter rcates919

    (@rcates919)

    Thanks Peter_L. I figured it out for anyone that cares.

    if (get_query_var('wood_type')) {
    		$taxonomy_term_id = $wp_query->queried_object_id;
    		$taxonomy = 'wood_type';
    		$unwanted_children = get_term_children($taxonomy_term_id, $taxonomy);
    		$unwanted_post_ids = get_objects_in_term($unwanted_children, $taxonomy);
    		// merge with original query to preserve pagination, etc.
    		query_posts( array_merge( array(
    			'post__not_in' => $unwanted_post_ids
    			), $wp_query->query) );
    }
Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Loop for displaying posts within a taxonomy’ is closed to new replies.