Hot answers tagged timestamp
5
Edit: wp_next_scheduled() returns the timestamp of the next scheduled job of a specified wp-cron job-arguments pair.
Please note that this differs slightly in functionality to the answer below, in that you have to provide the arguments passed to cron job's callback (if it has any). The original answer would provide the time of the next specified job ...
4
There is no filter for output of that function. You can fork (copy/rename/edit) it or add wrapper that will replace strings in output like this:
function short_time_diff( $from, $to = '' ) {
$diff = human_time_diff($from,$to);
$replace = array(
'hour' => 'h',
'hours' => 'h',
'day' => 'd',
'days' => 'd',
...
4
Looking at http://www.php.net/manual/en/datetime.formats.date.php I dont think strtotime will convert a DD/MM/YYYY to time correctly.
However it can do MM/DD/YYYY or YYYY/MM/DD.
Try using the date format of YYYY/MM/DD
Or if thats not to your liking then you can use the same date format but you will have to, on save, split up the date and convert it to ...
3
General WordPress rule:
when a function starts with get, it will return the value. If it starts with the, it echoes the value.
Here, you need get_the_date('d-m-Y') instead of the_date('d-m-Y').
3
The issue is that for correct output WP needs to process date through date_i18n() function. When you use date format, hardcoded in PHP code (not simply saved in PHP DATE_* constant) like 'c' - it's not available to your code and so for WP to process.
System-wide fix would be to re-process date with analogous format that can be accessed by WP code:
...
3
Yes, the event will trigger when the wp-cron process gets run. If something is preventing wp-cron from running, then it won't trigger at all. If you're having it not work, then something about your server configuration is preventing it from working.
For these cases, you can generally work around them by adding this define to your wp-config file:
...
3
WordPress actually has an obscure and little known function called human_time_diff() that does this. It takes two arguments; the first is the earlier timestamp, and the second is the later timestamp. Both should be Unix timestamps. The first argument is required, but the second is optional, and will use time() if left empty. So, for example, in the loop, you ...
2
function k99_relative_time() {
$post_date = get_the_time('U');
$delta = time() - $post_date;
if ( $delta < 60 ) {
echo 'Less than a minute ago';
}
elseif ($delta > 60 && $delta < 120){
echo 'About a minute ago';
}
elseif ($delta > 120 && $delta < (60*60)){
echo ...
2
WordPress automatically sets the server's timezone in PHP to GMT. This is to make any date manipulations consistent - and if changed, can cause some errors.
This means any native functions like date will interpret any date to be in the GMT (or UTC) format. Similarly the timezone for DateTime objects will be UTC.
You should not really change this, as this ...
2
An example, that uses the posts_where filter. If you need to extend a query using the posts_clauses filter, then just exchange $where with $pieces and set $pieces['where'] .= instead of $where .=. Just drop that into your functions.php file and add some conditional tag before querying the posts.
function filter_where( $where )
{
// Add some ...
2
You should store the time as a unix time stamp then you can use human_time_diff to compare.
echo human_time_diff( get_the_time('U'), current_time('timestamp') );
If the difference is more than 24 hours difference it will return the value in days.
2
As @amit wrote, the submission should have a daily counter that saves the count for that user, in the wp_usermeta table.
If you can run a cron job that runs daily, you can save the submission counter only. The daily cron can reset the counter on assigned time. But if you don't you should save the counter and the day also.
$current_user = ...
2
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()?
1
You're looking for wp_cron
if ( ! wp_next_scheduled( 'my_task_hook' ) ) {
wp_schedule_event( time(), 'daily', 'my_task_hook' );
}
add_action( 'my_task_hook', 'my_task_function' );
And then you define my_task_function() updating the post date.
1
You can get the post's creation date/time and compare it to the current date/time.
global $post;
$now = time(); // Current time in seconds since Epoch
$post_created = strtotime( $post->post_date ); // post's creation date in seconds since Epoch, so we're comparing apples to apples
$one_day_in_seconds = 24*60*60;
if ( ( $now - $post_created ) < ...
1
You need to express your condition in code. You are interested in comparing to current day, which can be expressed as PHP format Y z for example.
So your condition would be something like (not tested):
if ( the_time( 'Y z' ) === date_i18n( 'Y z' ) )
// today
else
// otherwise
1
the_date accepts four parameters. The fourth is an echo parameter-- false by default.
the_date('d-m-Y','','',true); // this will echo
Also, be aware that the_date and get_the_date are not equivalent functions, differing only in that the latter echos and the former does not (by default).
the_date
When there are multiple posts on a page published ...
1
Your computer's time and your server's time may not be exactly synchronized. So you may be seeing some pseudo-issues because of that.
I don't know where you are seeing "published 1 minute ago", or anything like that, in the backend. I see a "published on" date and a "last edited" date but those are 'hard' dates not dates relative to "right now" the way ...
1
Old answer (based on misconception that you wanted a cache buster): You can use add_query_arg() which adds/replaces query arguments.
<?php
/**
* Plugin Name: wpse_84670
* Version: 0.0.1
* Description: replace script/style version with time as a cache buster
*/
/**
* replace script or stylesheet version with current time
* @param string $url the source ...
1
WordPress sets the php timezone to UTC for internal calculations. So at 4pm PST, date() will be producing a date that reads 10pm UTC. Hence the event is considered past.
There are two ways to resolve this.
(The preferred method) Store dates in the database in UTC. Handle all date calculations in UTC, and convert to the desired timezone on output ...
1
This will compare today's date to the date meta key and select posts with a dates that are greater than or equal:
'meta_compare' => '>='
If you want to match only today's date, change it to just equal:
'meta_compare' => '='
1
To be able to query on your dates beyond a simple date comparison you should reverse the format of your date field. Dates should always follow the MySQL date format for reliable querying and sorting: YYYY-MM-DD HH:MM:SS
To query movies for today you would use a meta query:
$args = array(
'posts_per_page' => '-1',
'post_type' => 'movie',
...
1
PHP has a built-in date() function that formats Date-objects. In your case, you would use it as follows:
echo date('Y', 1322697600);
Since you're using these query arguments to build up an array of posts, and you want to filter specifically on that, I'd recommend building a function that triggers the loop based on your desired year filter.
I have used a ...
1
I don't know which forms you are using but the basic form submission loads the data into database.
To be able to track submission you need to store the data in database. In this case if you able to modify that form to store additional data such as date, user id, submissions etc. then you can further easily do mysql queries and determine how many submissions ...
1
http://codex.wordpress.org/Function_Reference/get_gmt_from_date
Replace all instances of get_the_date or the_date with echo get_gmt_from_date(get_the_date('Y-m-d H:i:s')). That's not a quick fix, it's a way to fix your sitemaps.
EDIT:
WordPress SEO runs it's raw dates from MySQL through a WP function called mysql2date, which in turn calls date_i18n. ...
1
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 and use strtotime() with this method instead.
The ...
1
I recently did exactly the same, you'll have to use custom query:
$date = time()-86400; /* today */
$querystr = "
SELECT $wpdb->posts.*
FROM $wpdb->posts, $wpdb->postmeta
WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id
AND ...
1
You don't have to store it as a timestamp to order by date, yyyy/mm/dd will work just fine.
As for converting the format:
$date = '2011/09/19';
$date = strtotime( $date );
echo date( 'F j, Y', $date );
see php's strtotime and date
EDIT- oh, maybe I misunderstood, thought you said timestamp, not date. anyway, the conversion code in the second part is ...
1
Most webservers have a so called logfile. When your site makes use of effective canonical permalinks, you can gain that information from the request URIs stored in the access-log-files.
This can be run as a janitor job in the background once a day/week while querying the URIs against your site's permalink structure and a genereate superset of all URIs as a ...
1
For starters try Core Control plugin to see if scheduled tasks are accurately assigned. Scheduled posts will show up as publish_future_post > check_and_publish_future_post() with post's ID as argument.
Only top voted, non community-wiki answers of a minimum length are eligible