WordPress.org

Support

Support » Themes and Templates » Multiple custom taxonomies

Multiple custom taxonomies

  • Hi all,

    After trying to sort out my problems with my page template, I decided to go with using custom taxonomies. I need to get pages by custom taxonomy, which I can do successfully, however, I have several loops on the page, yet only one shows can anyone help.

    <?php 
    
    if ( is_page() ) {
    	global $post;  
    
    	$args = array(
    	'tax_query' => array(
    		array(
    			'taxonomy' => 'top5',
    			'field' => 'name',
    			'terms' => $post->post_title
    		)
    	)
    );
    
    	$My_Query = new WP_Query( $args ); 
    
    	?>
    
    	<?php if ( $My_Query->have_posts() ) : ?>
    <?php rewind_posts(); ?>
    		<?php while ( $My_Query->have_posts() ) : $My_Query->the_post(); ?>
    <div class="comparison-stories"><div id="comparison-container_division">
    			<div class="comparison-post-block"><div class="wrapper"><div class="top-5-image">
    <?php the_post_thumbnail('medium'); ?></div></div>
     <div class="comparison-top5-text">
    	        <div class="wrapper"><div class="top-5-title"><p>
    <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p></div> </div>
     <div class="wrapper"><div class="comparison-content"><div class="comparisonexcerpttext">
    <?php the_excerpt(); ?></div></div></div></div></div></div>
    		<?php endwhile; ?>
    	    <?php else:
    	// Your fallback content here
    	?>
    	<?php endif; ?>
            <?php wp_reset_postdata(); ?>
    	<?php wp_reset_query(); ?>
    <?php } ?>
    <div style="width: 100% !important; float: left;">
    <div class="topfiveaffordabletitle"><h2>Top Five Affordable <?php the_title(); ?></h2></div>
    <?php 
    
    if ( is_page() ) {
    	global $post;  
    
    	$args = array(
    	'tax_query' => array(
    		array(
    			'taxonomy' => 'top5affordable',
    			'field' => 'name',
    			'terms' => $post->post_title
    		)
    	)
    );
    
    	$My_Query = new WP_Query( $args ); 
    
    	?>
    
    	<?php if ( $My_Query->have_posts() ) : ?>
    		<?php while ( $My_Query->have_posts() ) : $My_Query->the_post(); ?>
    <div class="comparison-stories"><div id="comparison-container_division">
    			<div class="comparison-post-block"><div class="wrapper"><div class="top-5-image">
    <?php the_post_thumbnail('medium'); ?></div></div>
     <div class="comparison-top5-text">
    	        <div class="wrapper"><div class="top-5-title"><p>
    <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p></div> </div>
     <div class="wrapper"><div class="comparison-content"><div class="comparisonexcerpttext">
    <?php the_excerpt(); ?></div></div></div></div></div></div>
    		<?php endwhile; ?>
    	    <?php else:
    	// Your fallback content here
    	?>
    	<?php endif; ?>
    	<?php wp_reset_postdata(); ?>
    <?php } ?>

    These are the first two loops of which there are four. The loops are almost exactly the same other than, the name of the taxonomy and the div classes.

  • The topic ‘Multiple custom taxonomies’ is closed to new replies.