Modified date comparison with post date not working properly
-
Hey, I am working in WPCode to get the modified/updated timestamp of a post to show alongside the author of the article. So far the code will print “Last Updated On: by X” correctly on each post. But upon further inspection I noticed that it is not doing the following comparisons between the posted date and the modified date. The script is simply outputting the updated date no matter if I use >= or <=, when I use > or < it will not show a date. It never shows the else case.
Some articles were scheduled so the modified date is before the post date. But it just seems that the comparison is not actually happening or it would pick the post date instead of the modified date. I have done quite a bit of research but was not able to find a solution for what seems to be a bug. Anything will help. Thanks in advanced.
$u_post_date = get_post_time( 'U' ); $u_modified_date = get_the_modified_time( 'U' ); add_filter( 'generate_post_date_output', function( $output, $time_string ) { if ( $u_modified_date >= $u_post_date ) { $updated_date = get_the_modified_time( 'F jS, Y' ); $updated_time = get_the_modified_time( 'h:i a' ); $time_string = '<time class="entry-date updated-date" datetime="%1$s" itemprop="dateModified">Last Updated On: %2$s</time>'; $time_string = sprintf( $time_string, esc_attr( $updated_time ), esc_html( $updated_date ) ); return sprintf( '<span class="posted-on">%s</span> ', $time_string ); } else { $posted_date = get_the_time( 'F jS, Y' ); $posted_time = get_the_time( 'h:i a' ); $time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">Published on: %2$s</time>'; $time_string = sprintf( $time_string, esc_attr( $posted_time ), esc_html( $posted_date ) ); return sprintf( '<span class="posted-on">%s</span> ', $time_string ); } }, 10, 2 );The blog I need help with is: (visible only to logged in users)
-
I am working in WPCode to get the modified/updated timestamp of a post to show alongside the author of the article. So far the code will print “Last Updated On: <Month day, year> by X” correctly on each post. But upon further inspection I noticed that it is not doing the following comparisons between the posted date and the modified date. The script is simply outputting the updated date no matter if I use >= or <=, when I use > or < it will not show a date. It never shows the else case.
Some articles were scheduled so the modified date is before the post date. But it just seems that the comparison is not actually happening or it would pick the post date instead of the modified date. I have done quite a bit of research but was not able to find a solution for what seems to be a bug. Anything will help. Thanks in advanced.
$u_post_date = get_post_time( 'U' ); $u_modified_date = get_the_modified_time( 'U' ); add_filter( 'generate_post_date_output', function( $output, $time_string ) { if ( $u_modified_date >= $u_post_date ) { $updated_date = get_the_modified_time( 'F jS, Y' ); $updated_time = get_the_modified_time( 'h:i a' ); $time_string = '<time class="entry-date updated-date" datetime="%1$s" itemprop="dateModified">Last Updated On: %2$s</time>'; $time_string = sprintf( $time_string, esc_attr( $updated_time ), esc_html( $updated_date ) ); return sprintf( '<span class="posted-on">%s</span> ', $time_string ); } else { $posted_date = get_the_time( 'F jS, Y' ); $posted_time = get_the_time( 'h:i a' ); $time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">Published on: %2$s</time>'; $time_string = sprintf( $time_string, esc_attr( $posted_time ), esc_html( $posted_date ) ); return sprintf( '<span class="posted-on">%s</span> ', $time_string ); } }, 10, 2 ); -
Hi there,
Apologies, but we can’t help with your issue directly because we don’t host devicemag.com on our WordPress.com managed hosting.
To explain, we are a fully managed hosting provider and use a custom server environment that is optimized for WordPress, provides built-in security and performance improvements, as well as in-house support for your site questions. You can learn more about the performance and security benefits of our managed hosting here: https://wordpress.com/hosting/
Because of the way we’ve optimized our service, we also use a customized version of WordPress that is different (under the hood) from what you use at your current provider. As a result, we do not have access to your site and are not familiar with the source of your issue.
You definitely have the option to move your site to us so we can provide in-house help, and we offer a migration plugin that will help you move your site to our managed hosting in just a few clicks.
Use the Move to WordPress.com plugin to migrate a self-hosted WordPress site to WordPress.com. Follow the steps in this guide to import your site (including your content, media, plugins, and theme) directly from your wp-admin dashboard. Prerequisites To follow the steps in this guide, you will need: Your source site: a WordPress site with any other hosting provider (referred to as a seUnfortunately though, as it stands now, we are not able to help since it is hosted elsewhere. The good news is that help is available here at the open-source WordPress forums: https://wordpress.org/support/forum/how-to-and-troubleshooting
The folks in that forum are more familiar with these kinds of issues and are in the best position to help.
Thanks!
- The topic ‘Modified date comparison with post date not working properly’ is closed to new replies.
