WordPress.org

Ready to get started?Download WordPress

Forums

Custom Taxonomy heading (1 post)

  1. accounts@push
    Member
    Posted 1 year ago #

    hi guys,

    My site is set out to have a portfolio section,

    each portfolio item needs to correspond to a custom product category which contains a product we offer.

    currently i am using an archive of each product to display the products name and the products description, which i had working fine, however my client pointed out once testing this feature that if a portfolio item is assigned to more then one of the product categories the archive page displays both of the headings and both of the descriptions.

    the loop works fine because i want all the posts even the ones shared with other products to be displayed however using the following code it get the other products category displayed as well

    <h2><?php
    $terms = get_the_terms( $post->ID, 'work_type' );
    
    if ( $terms && ! is_wp_error( $terms ) ) : 
    
    	$tax_header = array();
    
    	foreach ( $terms as $term ) {
    		$tax_header[] = $term->name;
    	}
    
    	$out_tax_header = join( ", ", $tax_header );
    ?>
    <?php echo $out_tax_header; ?>
    <?php endif; ?></h2>
    					<?php
    $terms = get_the_terms( $post->ID, 'work_type' );
    
    if ( $terms && ! is_wp_error( $terms ) ) : 
    
    	$tax_descr = array();
    
    	foreach ( $terms as $term ) {
    		$tax_descr[] = $term->description;
    	}
    
    	$out_tax_descr = join( ", ", $tax_descr );
    					?><p><?php echo $out_tax_descr; ?></p>
      <?php endif; ?>

    i then found out that the second category when archived does not display any information from the first one . you can see this here - basically i want to show the correct posts but so far nothing is working

Topic Closed

This topic has been closed to new replies.

About this Topic