Skip Navigation

[Resolved] Modification date in CRED Forms

This thread is resolved. Here is a description of the problem and solution.

Problem: I would like to show the last modification date for a specific post using a custom shortcode, but when I update the post with Forms the date does not seem to change.

Solution:
Be sure the shortcode is set up to accept a post ID shortcode attribute, since it is placed on a different post.

// Add Shortcode
function wp_last_modified( $atts ) {
 
    // Attributes
    $atts = shortcode_atts(
        array(
            'id' => '',
        ),
        $atts
    );
 
    return  get_the_modified_date('j F Y H:i:s', $atts['id']);
}
add_shortcode( 'wp_last_modified', 'wp_last_modified' );
[wp_last_modified id="15"]

Relevant Documentation:
https://codex.wordpress.org/Function_Reference/get_the_modified_date
https://codex.wordpress.org/Function_Reference/the_modified_date

This support ticket is created 6 years, 3 months ago. 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.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 5 replies, has 3 voices.

Last updated by tomaszB-4 6 years, 2 months ago.

Assisted by: Christian Cox.

Author
Posts
#1117039

I have Custom Post Type and Custom Fields in it.
I modify the posts using CRED form and I need to print out modyfication date.
I do not always update the post body, sometimes only one of the Custom Fields is updated.

I have no idea how to do it. Maybe there is some PHP code to insert into the file?
This is very important to me, because user visiting the website must see the date and time of modification of the post.
I will be grateful for every hint.

#1117294

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Tomasz,

Thank you for contacting our support forum.

You try using this custom shortcode to get the modified date.

// Add Shortcode
function wp_last_modified( $atts ) {

	// Attributes
	$atts = shortcode_atts(
		array(
			'id' => '',
		),
		$atts
	);

	return  the_modified_date();

}
add_shortcode( 'wp_last_modified', 'wp_last_modified' );

Then you can use it like this [wp_last_modified]

Please let me know if this helps.

Thanks,
Shane

#1118168

Hi Shane and thanks for fast reply!

Unfortunately, this code does not work as I would like.
I've already inserted the code directly into the template files:

the_modified_date('j F Y H:i:s')

This code works the same as the code from you:

The date and time of the modification is changed when you edit the post directly in WordPress.
But when you edit a post while in the custom form built in the Toolset, the date and time are no longer refreshed.

Could you do something about it please?

#1119143

Hi, Shane is on vacation this week so I will try to help.

But when you edit a post while in the custom form built in the Toolset, the date and time are no longer refreshed.
Even if you only modify a custom field value, CRED should update the post modification date and time to reflect that change. If this is not happening on your site, I will need to take a closer look.

May I see this Form on your site to understand how it is implemented? If that's okay, please provide login credentials in the private reply fields here. Let me know which Form you are referring to, and where I can see the Form on your site. I will also need to know where you added this code in your template PHP files.

#1119316

Okay check now. There were two problems:
1. The wp_last_modifed shortcode was placed on the page Tabelka Gdańska 26, so it was showing the last modified date for Tabelka Gdańska 26, not the last modified date for Edycja walut. I updated the shortcode in Tabelka Gdańska 26 to supply the correct post ID as a shortcode attribute:

[wp_last_modified id="15"]

2. The wp_last_modified shortcode was returning the_modified_date, but should return get_the_modified_date instead. This is why you had to place the shortcode after the View, which seems backwards. I made this change for you, and moved the shortcode before the View where it should be:

return  get_the_modified_date('j F Y H:i:s', $atts['id']);

https://codex.wordpress.org/Function_Reference/get_the_modified_date
https://codex.wordpress.org/Function_Reference/the_modified_date

Be sure to download the updated functions.php file into your local file repository!

#1119889

It works beautifully! Yes, I've mixed up the place to embed the code, stupid mistake 🙂 Thank you very much Christian! Without your help, I would probably work on the problem for a very very long time. And there is the case of the_modified_date and get_the_modified_date. It's great to have such support as here on the Toolset Forum. Thanks again!