Title: [Plugin: Media Tags] Conditional Testing
Last modified: August 19, 2016

---

# [Plugin: Media Tags] Conditional Testing

 *  [triggame](https://wordpress.org/support/users/triggame/)
 * (@triggame)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/plugin-media-tags-conditional-testing/)
 * Hi All
 * Maybe somebody can help me here?
    I’ve been trying to do this for days now with
   no success. I’m trying to use the “in_mediatag()” function to add a class, but
   just not getting it right. There don’t seem to be any examples on the site. I’d
   like to use it in a function that was shown at [http://digwp.com/2009/08/awesome-image-attachment-recipes-for-wordpress/](http://digwp.com/2009/08/awesome-image-attachment-recipes-for-wordpress/)
 * This is what I’m trying:
 *     ```
       if (in_mediatag('choice')){
       echo ' my-choice-item';
       }
       ```
   
 * In context:
 *     ```
       function gallery_toolbox($size = thumbnail) {
   
       	if($images = get_children(array(
           'order' => 'ASC',
       		'orderby' => 'menu_order',
       		'post_parent'    => get_the_ID(),
       		'post_type'      => 'attachment',
       		'numberposts'    => -1, // display the amount to show per post
       		'post_status'    => null,
       		'post_mime_type' => 'image',
       	))) {
       		foreach($images as $image) {
       			$attimg   = wp_get_attachment_image($image->ID,$size);
       			$atturl   = wp_get_attachment_url($image->ID);
       			$attlink  = get_attachment_link($image->ID);
       			$atttitle = apply_filters('the_title',$image->post_title);
       			$postlink = get_permalink($image->post_parent);
       			$posttitle= get_the_title($image->post_parent);
   
       			echo '<dl class="gallery-item';
       			if (in_mediatag('choice')){
       			echo ' my-choice-item';
       			}
       			echo '"><dt class="gallery-icon"><a href='.$attlink.' >'.$attimg.'</a></dt><dd class="gallery-caption"><a href='.$attlink.'>'.$atttitle.'</a></dd></dl>';
   
       		}
       	}
       }
       ```
   
 * [http://wordpress.org/extend/plugins/media-tags/](http://wordpress.org/extend/plugins/media-tags/)

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Thread Starter [triggame](https://wordpress.org/support/users/triggame/)
 * (@triggame)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/plugin-media-tags-conditional-testing/#post-1616662)
 * I cannot figure out what the equivalent function to `has_tag()` would be.
 *  Plugin Author [Paul Menard](https://wordpress.org/support/users/pmenard/)
 * (@pmenard)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/plugin-media-tags-conditional-testing/#post-1616686)
 * triggame,
 * I was hoping WP core would come up with a generic function like has_tag which
   would work for other Taxonomies. Since Media-Tags uses the new Taxonomy system
   I’ve cloned the has_tag WP function to has_mediatag()
 * So instead of calling in_mediatag(‘choice’) use has-mediatag(‘choice’, $image-
   >ID);
 * Note you do need to provided the second parameter since has_tag assumed you are
   working with the global $post object by default.
 * function has_mediatag( $tag = ”, $_post = null ) {
 *  if ( $_post ) {
    $_post = get_post( $_post ); } else { $_post =& $GLOBALS[‘post’];}
   if ( !$_post ) return false;
 *  $r = is_object_in_term( $_post->ID, MEDIA_TAGS_TAXONOMY, $tag );
 *  if ( is_wp_error( $r ) )
    return false; return $r; }
 *  Thread Starter [triggame](https://wordpress.org/support/users/triggame/)
 * (@triggame)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/plugin-media-tags-conditional-testing/#post-1616699)
 * THANK YOU, THANK YOU, THANK YOU!!!!!!!!!!!!!!!!!!!
    You have absolutely no idea
   how glad I am!
 * No clue what you did with the second parameter bit, but I just pasted it inside
   my functions.php file and it worked perfectly!
 * Thanks so much Paul! …and thanks for getting back to me so quickly.
 * John.
 *  Plugin Author [Paul Menard](https://wordpress.org/support/users/pmenard/)
 * (@pmenard)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/plugin-media-tags-conditional-testing/#post-1616705)
 * You are very welcome. Thank you for using my Media-Tags plugin. One other note.
   I’m including the function has_mediatag into the upcoming 3.0 release of the 
   plugin. So as not to conflict with your version in your theme’s functions.php
   can you give your local function a different name.
 *  Thread Starter [triggame](https://wordpress.org/support/users/triggame/)
 * (@triggame)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/plugin-media-tags-conditional-testing/#post-1616763)
 * Will do!
    Thanks again.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘[Plugin: Media Tags] Conditional Testing’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/media-tags.svg)
 * [Media Tags](https://wordpress.org/plugins/media-tags/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/media-tags/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/media-tags/)
 * [Active Topics](https://wordpress.org/support/plugin/media-tags/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/media-tags/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/media-tags/reviews/)

 * 5 replies
 * 2 participants
 * Last reply from: [triggame](https://wordpress.org/support/users/triggame/)
 * Last activity: [15 years, 9 months ago](https://wordpress.org/support/topic/plugin-media-tags-conditional-testing/#post-1616763)
 * Status: not resolved