Hi there. I'm creating a view for a widget to display some custom post types and I would like to display the date in a form like "xyz published a new post 2 hours 15 minutes ago" . How can I do it?
Dear Gian Luca,
We have a shortcode for post date wpv-post-date, but you can not achieve what you want using it. See the documentation about our shortcode: https://toolset.com/documentation/views-shortcodes/#vf-154574
You could create a custom shortcode and use human_time_diff() wordpress function, like this below:
add_shortcode( 'display-human-diff', 'display_human_diff_func' );
function display_human_diff_func( $atts ) {
return human_time_diff( get_the_time('U'), current_time('timestamp') ) . ' ago';
}
You must add the code below in functions.php. So you could call it like this:
xyz published a new post [display-human-diff].
Hello Adriano,
Thanks for your reply. Do I have to pass any parameter along with the shortcode? Does it take by default the post date value?
Nver mind Adriano! I tried it like this and it works like a charm! Thanks a ton!! :o)