I am trying to: https://toolset.com/forums/topic/shortcode-for-current-time-modified-date/#post-27061
Link to a page where the issue can be seen: hidden link
I expected to see: The time I actually posted the post.
Instead, I got: 48 years. When it was posted the day I am submitting this ticket.
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi Donald,
Thank you for contacting our support forum.
It seems that you are using the function incorrectly based on the way its meant to be used or rather the parameters that it accepts.
human_time_diff( int $from, int $to = '' )
So you see the first parameter should be the from and the second should be to.
Take a look at the link below for example usage of this code.
https://developer.wordpress.org/reference/functions/human_time_diff/
Thanks,
Shane
This is simply what the other support ticket said.
Where would I need to change the code to add that?
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi Donald,
I'm imagining that you want to compare a timestamp to our current time.
Is it that you want to do it with the published date or the modified date?
Please let me know.
Thanks,
Shane
Published date please. There won't be any modifying the post once it is published.
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi Donald,
Try using this.
human_time_diff( get_the_time('U'), current_time('timestamp') ) . ' ago';
Please let me know if it helps
Thanks,
Shane
Doesn't look like it worked
add_shortcode('time-ago', 'time_ago_shortcode');
function time_ago_shortcode($atts, $content = null) {
human_time_diff( get_the_time('U'), current_time('timestamp') ) . ' ago';
}
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi Donald,
You need to add the return statement as well.
return human_time_diff( get_the_time('U'), current_time('timestamp') ) . ' ago';
Thanks,
Shane
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi Donald,
Awesome if there are no further issues then you can mark this ticket as resolved.
Thanks,
Shane