• Resolved Od3n

    (@od3n)


    how to use has_tag() for custom taxonomy? let say i want it to display meta box if the post have tag.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    🏳️‍🌈 Advisor and Activist

    I think you want get_terms actually

    http://codex.wordpress.org/Function_Reference/get_terms

    Thread Starter Od3n

    (@od3n)

    see my code here :

    <?php if(has_tag()) { ?>
    					<div class="metadata">
    						<?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
    						<?php the_tags( '<p>Tags: ', ', ', '</p>'); ?>
    					</div><!-- .metadata -->
    					<?php }

    i want do the same for my custom tag.

    Thread Starter Od3n

    (@od3n)

    ok figured it out.

    function has_product_tag( $product_tag, $_post = null ) {
    	if ( !empty( $product_tag ) )
    		return false;
    
    	if ( $_post )
    		$_post = get_post( $_post );
    	else
    		$_post =& $GLOBALS['post'];
    
    	if ( !$_post )
    		return false;
    
    	$r = is_object_in_term( $_post->ID, 'product_tag', $product_tag );
    
    	if ( is_wp_error( $r ) )
    		return false;
    
    	return $r;
    }
    <?php if(has_product_tag(null)) { ?>
    // some code here
    <?php } ?>
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘has_tag for custom taxonomies’ is closed to new replies.