Skip Navigation

[Gelöst] Last updated and last updated author

This support ticket is created vor 5 Jahre, 3 Monate. There's a good chance that you are reading advice that it now obsolete.

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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 2 Antworten, has 2 Stimmen.

Last updated by Akhil vor 5 Jahre, 3 Monate.

Assisted by: Waqar.

Author
Artikel
#1176123

Hi Waqar,

i picked this 2 snippets from the search here.


add_shortcode('the-modified-author', function( $atts = [], $content=null ) {
    return get_the_modified_author();
});


add_shortcode('wpv-post-modified', 'wpv_post_modified_shortcode');
function wpv_post_modified_shortcode($atts) {
    static $tempDate = 0;   
    if (empty($atts['format'])) {
        $atts['format'] = get_option('date_format');
    }
    if( $tempDate < get_the_modified_date('U', true) )
    {
        $tempDate = get_the_modified_date('U', true);
        return date($atts['format'], $tempDate);
    }
    return '';
}

i tried to use them but this code doesn't work in layout cell.,. any idea why ?
updated on [wpv-post-modified format="d-m-Y h:i:s A (T)"] by [the-modified-author]

update: found updated views shortcode:https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-post-date

Thank You in advance!

#1176727

Waqar
Supporter

Languages: Englisch (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Dee,

Thanks for asking! I'd be happy to help.

I've tested the code of both your shortcodes and they work as expected from a layout cell as well as inside a view.

I would suggest a slight adjustment to the second shortcode though, as the original code won't work if the same shortcode is used twice on a page.


add_shortcode('wpv-post-modified', 'wpv_post_modified_shortcode');
function wpv_post_modified_shortcode($atts) {
       
    if (empty($atts['format'])) {
        $atts['format'] = get_option('date_format');
    }
    if( get_the_modified_date('U', true) )
    {
        $tempDate = get_the_modified_date('U', true);
        
        return date($atts['format'], $tempDate);
    }
}

Important note: These shortcodes will only work if they are used inside a loop, whether its a view or a layout, which mean the current post's ID is available to enclosed functions.

The difference between your custom shortcode "wpv-post-modified" and the builtin shortcode "wpv-post-date" is that first one will show the date and time when a post was last edited, while the second one will show it's published date and time.

regards,
Waqar

#1176733

My issue is resolved now. Thank you Mr Waqar

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.