• 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://ww.wp.xz.cn/plugins/wp-tiles/

Viewing 1 replies (of 1 total)
  • Thread Starter carosea

    (@carosea)

    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.