Title: has_tag Help
Last modified: August 20, 2016

---

# has_tag Help

 *  [adim32](https://wordpress.org/support/users/adim32/)
 * (@adim32)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/has_tag-help-1/)
 * <?php if (has_tag(array(‘tag1’, ‘tag2′,’tag3’))) $tg = $thetag(display the the
   tag that has);
    else $tg = ‘no tag found’;?>
 * If someone can help me. i want the $tg variable get the tag that was found. Sorry
   for my bad english

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

 *  [egado](https://wordpress.org/support/users/egado/)
 * (@egado)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/has_tag-help-1/#post-2725664)
 * Hmm… hope I understand your problem…
 * <?php
    if( has_tag() ) { // IF THE POST HAS TAGS $tg = get_the_tags(); } else{//
   IF NO TAGS $tg = ‘no tags found’; } ?>
 * Pls try this… and let me know if it helps 😉
 *  Thread Starter [adim32](https://wordpress.org/support/users/adim32/)
 * (@adim32)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/has_tag-help-1/#post-2725667)
 * Is not working. Instead i get the tag i get Array
 *  [egado](https://wordpress.org/support/users/egado/)
 * (@egado)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/has_tag-help-1/#post-2725673)
 * Yes, I just put the tags in your $tg and added no output…
    If you dont really
   need the tags to be on your $tg you can use this way of showing or not showing
   the tags… couse the_tags(); will do that for you…
 *     ```
       <?php
       if( has_tag() ) {
         // IF THE POST HAS TAGS
         the_tags();
       }
       else {
         // IF NO TAGS
         echo 'no tags found';
       }
       ?>
       ```
   
 *  Thread Starter [adim32](https://wordpress.org/support/users/adim32/)
 * (@adim32)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/has_tag-help-1/#post-2725676)
 * i need to find if has one of the tag that i specific and show him. else no tags
   found
 *  Thread Starter [adim32](https://wordpress.org/support/users/adim32/)
 * (@adim32)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/has_tag-help-1/#post-2725677)
 * i found this
 * _[[code moderated - please see forum guidelines for posting code]](http://codex.wordpress.org/Forum_Welcome#Posting_Code)_
 * but this will show me Array if the tag not found and i want to show "no tag found".
   
   Can you help me?
 *  [egado](https://wordpress.org/support/users/egado/)
 * (@egado)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/has_tag-help-1/#post-2725679)
 * Ok, now i got it…
    i will try a solution… pls wait 😉
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/has_tag-help-1/#post-2725680)
 * try:
 *     ```
       <?php if (has_tag(array('tag1', 'tag2','tag3')))
       foreach( get_the_tags() as $tag ) {
       if( in_array( $tag->name, array('tag1', 'tag2','tag3') ) ) //use tag title - watch capitals and spelling
       { $tg = $tag->name; break; }
       }
       else $tg = 'no tag found'; ?>
       ```
   
 *  Thread Starter [adim32](https://wordpress.org/support/users/adim32/)
 * (@adim32)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/has_tag-help-1/#post-2725910)
 * alchymyth this is work verry well.
    Thanks alchymyth and egado for help.

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

The topic ‘has_tag Help’ is closed to new replies.

 * 8 replies
 * 3 participants
 * Last reply from: [adim32](https://wordpress.org/support/users/adim32/)
 * Last activity: [14 years, 1 month ago](https://wordpress.org/support/topic/has_tag-help-1/#post-2725910)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
