WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] has_tag for custom taxonomies (4 posts)

  1. Od3n
    Member
    Posted 4 years ago #

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

  2. I think you want get_terms actually

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

  3. Od3n
    Member
    Posted 4 years ago #

    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.

  4. Od3n
    Member
    Posted 4 years ago #

    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 } ?>

Topic Closed

This topic has been closed to new replies.

About this Topic