Home › Toolset Professional Support › [Resolved] Show date of last modified post in a loop which is sorted by custom field
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 |
---|---|---|---|---|---|---|
- | 10:00 – 13:00 | 10:00 – 13:00 | 10:00 – 13:00 | 10:00 – 13:00 | 10: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/Kolkata (GMT+05:30)
Related documentation:
This topic contains 13 replies, has 2 voices.
Last updated by Purchasing WCER 3 years, 12 months ago.
Assisted by: Minesh.
I would like to show the date of the last modified post in a loop. The loop is ordered descending by custom field "year"
documentation following: https://toolset.com/forums/topic/adding-a-shortcode-for-the-last-modified-date/
I added this code to the page where the loop is: <p>Last modified: [custom-posttype-modified format="d-m-Y h:i:s A (T)"]</p>
And this code to the functions.php file
add_shortcode('custom-posttype-modified', 'custom_posttype_modified_shortcode');
function custom_posttype_modified_shortcode() {
query_posts(array('post_type'=>'curricula','orderby' => 'year', 'order' => 'DESC' , 'showposts' => 1));
if (have_posts()) :
while (have_posts()) : the_post();
$return_string = get_the_modified_date();
endwhile;
endif;
wp_reset_query();
return $return_string;
}
The issue is that the output is showing August 13, 2020 as the last modified date. This is neither the latest published date (August 12, 2020) nor the latest modified date (January 6, 2020).
What am I missing?
Sample page here: hidden link
Hello. Thank you for contacting the Toolset support.
I'm not sure why you are using the shortcode as Toolset offers the shortcode that [wpv-post-date] using which you can display the modified date:
=> https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-post-date
For example:
[wpv-post-date type="modified"]
What if you try to use the above shortcode and see if that help you to resolve your issue.
If no, I will require admin access details with FTP to check whats going wrong there.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I have set the next reply to private which means only you and I have access to it.
I will require admin access details to access the backend.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I have set the next reply to private which means only you and I have access to it.
updated info
Can you please check now: hidden link
I've adjusted the shortcode you added to the functions.php file as given under:
add_shortcode('custom-posttype-modified', 'custom_posttype_modified_shortcode'); function custom_posttype_modified_shortcode($atts) { global $post; return get_the_modified_date($atts['format'],$post->ID); }
Do you see it working as expected?
This is not working for districts with more than one post in the loop. If you look at my original question and this page hidden link it
is now showing August 4, 2020 as the last modified date. This is neither the latest published date (August 12, 2020) nor the latest modified date (January 6, 2020) of the collection of child posts in the loop. It should show January 6 because that is the date I edited the first entry.
So, lets understand again you problem first and correct me if I'm wrong.
You want to display singe post of your desired post type in this case it's the district post type:
=> hidden link
To display that singe post type, you created a single post Content Template using blocks that is used to display the single post of post type district.
=> hidden link
With that content template, you added the shrotcode:
[custom-posttype-modified format="d-m-Y h:i:s A (T)"]
The above shortcode should display the last modified date of the single post you currently display. - Correct?
Please correct me if required.
Not quite. The district is the parent post with curriculum post children. The page: hidden link shows a loop view of that district's children (curriculum posts). I want to show the last modified date of the last modified child post at the top of the loop. I want to show only that one date, not a last modified date for every child post.
Ok - I got it. You want to display the modified date of your last child post at top of the page.
I checked but it looks like on your server there is no permission to add custom code or file edits.
I will require to edit your theme file and for that I will require FTP access details as if any error may occur while I editing if the whole site will be down so its preferable that I should edit your theme file using FTP access details.
I have set the next reply to private which means only you and I have access to it.
I'm not sure I'll be able to give you FTP access. What theme files would you like to edit? Functions.php is available under appearance>Theme Editor. I can add additional files there if that is helpful. Alternately you can tell me what edits should be made. Thank you.
Yes - functions.php file is available for edit but while testing if there is something goes wrong and once I save the file, I will not be able to access it. That is why I want FTP access details.
Toolset offers "Custom Code" section and even I try to add the snippet there but it seems you set disallow file edits on your site.
=> https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/
Even if you remove the disallow file edits and make sure that custom code section works and you able to add snippet there then I will not require FTP access details.
Editing permissions have been updated. Please try adding code to the "Custom Code" section of Toolset now.
I've added the following code to "Custom Code" section offered by Toolset:
=> hidden link
add_shortcode('custom-posttype-modified', 'custom_posttype_modified_shortcode'); function custom_posttype_modified_shortcode($atts) { global $post; $query = new WP_Query( array( 'post_type' => 'curricula', 'showposts' => 1, //new toolset_relationships query argument 'toolset_relationships' => array( 'role' => 'child', 'related_to' => $post->ID, // this will work only with relationships that have existed before the migration // if possible, use the relationship slug instead of an array 'relationship' => 'district-curricula' ), 'orderby' => 'modified', 'order' => 'DESC', ) ); $posts = $query->post; return get_the_modified_date($atts['format'],$posts->ID); }
Can you please confirm you see now the expected modified date:
=> hidden link
That works great. Thank you so much for the help!