Skip Navigation

[Resolved] Date Display Problem

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

This topic contains 4 replies, has 2 voices.

Last updated by Adriano 6 years, 2 months ago.

Assigned support staff: Adriano.

Author
Posts
#228383

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?

#228439

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].
#228442

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?

#228443

Nver mind Adriano! I tried it like this and it works like a charm! Thanks a ton!! :o)

#228444

Nice, you are welcome!