Display published time for today’s posts only
$post_date = get_the_date(‘d/m/Y’); $today = date(‘d/m/Y’); if ( $post_date == $today ) { echo get_the_date(‘h:m’); } else { echo get_the_date(); }
$post_date = get_the_date(‘d/m/Y’); $today = date(‘d/m/Y’); if ( $post_date == $today ) { echo get_the_date(‘h:m’); } else { echo get_the_date(); }
human_time_diff() only returns a single {number} {unit} string back. It rounds to nearest whole unit, instead of breaking down the difference precisely. To get an exact duration difference, you’ll need to use your own function. As this is a popular need in PHP, there’s lots of solutions online – here’s a clever one I found: … Read more
You have to return the formatted date string, the following will work: // define the get_comment_time callback function filter_get_comment_time( $date, $d, $gmt, $translate, $comment ) { $d = “g:i:s”; $date = mysql2date($d, $date, $translate); return $date; }; // add the filter add_filter( ‘get_comment_time’, ‘filter_get_comment_time’, 10, 5);
In short, the server shows 13h (correct in current time in São Paulo DST), but PHP shows15h and WordPress shows 12h. This is intentional, and needs additional clarification, but to expand you have: The server local time UTC timestamps Localised WP time These needs to be separate, e.g. if I host a Japanese website on … Read more
Take a look at this page https://codex.wordpress.org/Function_Reference/wp_update_post . There is an example of how to update the post. All you need is the post ID that you want to update, and some code to change certain text in the post.You will want to get the post’s data (an array), then change the $post_content array item … Read more
the_title doesn’t work that way: the_title( $before, $after, $echo ); $before is the text that comes before the title, but you didn’t give it a string/text, you gave it a post object. Post objects aren’t strings, PHP doesn’t know what to do so it stops and prints an error instead. For the_title to work, you … Read more
So what you need to do is make your life easier and instead of searching everything within every instance of .pp-post-content or .pp-post-content p, let’s wrap the times or the times in question with a span tag. Like you suggested in your comments <span class=”tas-event-time”> is sufficient enough. Now, in your .js file, you want … Read more
If all you need to do is check the difference, rather than display or modify anything, then you don’t need to do anything complicated with date_diff(). All you need to do is compare the number of seconds returned by get_post_time() for each date. get_post_time() returns the Unix timestamp for the date, which is simply the … Read more
the_time does not display the current date, it displays the date of the current post, and 404 pages do not have a current post. For this reason, if it ever returned a date on the 404 page then it would be a bug. Instead you should use the PHP functions that come with PHP to … Read more
WordPress will order search results by newest post first by default, so if your results are in a different order then it looks like another plugin is affecting them. Have you tried searching with all other plugins disabled? If you’re using Relevanssi, then it won’t order results by date as Relvanssia overrides this with its … Read more