Title: using post Tag as variable in function
Last modified: August 22, 2016

---

# using post Tag as variable in function

 *  [carosea](https://wordpress.org/support/users/carosea/)
 * (@carosea)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/using-post-tag-as-variable-in-function/)
 * Mike
    My problem now is using a tag set up on the post (called birthdate and 
   storing a date in the format YYYY-MM-DD – which is equivalent to date(‘Y-m-d’))
   instead of harcoding the date as below 1998-11-30each selected post whose birthday
   it is will have a different date. I can’t seem to get the tag into the code if
   I replace the date with $birthdate I get a code error…
 *     ```
       function get_age($years)
       {
       $diff = abs(strtotime(date('Y-m-d')) - strtotime('1998-11-30'));
       $years = floor($diff / (365*60*60*24));
       $months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
       $days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));
       $results = $years." years ";
       return $results;
       }
       ```
   
 * [https://wordpress.org/plugins/wp-tiles/](https://wordpress.org/plugins/wp-tiles/)

Viewing 1 replies (of 1 total)

 *  Thread Starter [carosea](https://wordpress.org/support/users/carosea/)
 * (@carosea)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/using-post-tag-as-variable-in-function/#post-5941174)
 * Mike
    I am getting a bit confused here – until the wp_query is run in my_custom_content.
   php the sytem won’t know which posts satisfy the ‘having a birthday today’ criteria.
   When a post does satisfy that criteria I need to get the actual birthdate (which
   I will store either have as a post tag or a custom field whichever is the easiest)
   and set that as an $opts and pass it through to the_wp_tiles for displaying the
   age on each tile. My problem is not in the displaying of the age as such (I have
   done that with a fixed date) but in the retrieving and passing a variable (of
   the birthdate )at the time of running the wp_query into the function to calculate
   the age. I have tried passing a variable into the function in the format YYYY-
   MM-DD’ but that fails and produces an age calculated based on 1970.

Viewing 1 replies (of 1 total)

The topic ‘using post Tag as variable in function’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/wp-tiles_8f8e84.svg)
 * [WP Tiles](https://wordpress.org/plugins/wp-tiles/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-tiles/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-tiles/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-tiles/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-tiles/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-tiles/reviews/)

## Tags

 * [tag](https://wordpress.org/support/topic-tag/tag/)
 * [variable](https://wordpress.org/support/topic-tag/variable/)

 * 1 reply
 * 1 participant
 * Last reply from: [carosea](https://wordpress.org/support/users/carosea/)
 * Last activity: [11 years, 2 months ago](https://wordpress.org/support/topic/using-post-tag-as-variable-in-function/#post-5941174)
 * Status: not resolved