How to show different timestamp
This should do it. // See if the post is older than 24 hours. if ( get_post_time() <= strtotime( ‘-1 day’ ) ) { echo ‘Published more than 24 hours ago.’; } else { echo ‘Published within the last 24 hours.’; }
This should do it. // See if the post is older than 24 hours. if ( get_post_time() <= strtotime( ‘-1 day’ ) ) { echo ‘Published more than 24 hours ago.’; } else { echo ‘Published within the last 24 hours.’; }
You could also do it using human_time_diff hook, but it would make it global: function my_time_diff_mins( $since, $diff, $from, $to ) { return $since . ($from > $to ? ‘ from now’ : ‘ ago’); } add_filter( ‘human_time_diff’, ‘my_time_diff_mins’, 10, 4 );
It looks like your query is for ALL posts in that post type as you are overwriting $posts when using $posts = get_posts(). You need to pass the Taxonomy parameter correctly as explained here like this: $args = array( ‘post_type’ => ‘post’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘people’, ‘field’ => ‘slug’, ‘terms’ => ‘bob’, … Read more
Since WordPress is a server-side framework/CMS, it likely doesn’t have the functionality you’re looking for. If you’re looking for ways to obtain this information, the most reliable would likely be to ask the user. To make it as painless as possible for the user, this functionality could be achieved via client-side scripting (ie. JavaScript) where … Read more
I am referenceing http://pastebin.com/dRfLY1et In line 74 either delete echo ‘true’; or comment it out. That should keep it from displaying.
As far as I know that’s as deep as wordpress can go, you will have to use php to get it into weeks/months/etc. You have 2 options: Use human_time_diff and create a function that just calculates the differences(pretty easy to figure out 7 days = 1 week, etc). I would honestly not use human_time_diff though … Read more
the_time() is for outputting the time at which a post was written, and gets this value from the global $post. I’m guessing you just want php’s date()?
First things first, I suppose that your function already works – I did not debug it, but wanted to point you in the right direction of WordPress scheduling of events. You should use wp-cron for that. It let’s you schedule events, and let them be handled by WordPress. Please keep in mind that this is … Read more
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
$mytimestamp = date(get_option(‘date_format’), strtotime($date)) . ‘ at ‘ . date(get_option(‘time_format’), strtotime($date));