Tag Info

Hot answers tagged

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

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: ...


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 ...


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', ...


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

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 ...


3

$mytimestamp = date(get_option('date_format'), strtotime($date)) . ' at ' . date(get_option('time_format'), strtotime($date));


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: ...


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

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

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 output of current_time('timestamp') should be time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ); according to WP 3.5.2, so you should check your get_option( 'gmt_offset' ) settings. Also current_time('timestamp', 1 ) should give you time().


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()?


2

Yes, event is triggered as soon as possible after scheduled time has passed.


2

I am referenceing http://pastebin.com/dRfLY1et In line 74 either delete echo 'true'; or comment it out. That should keep it from displaying.


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

You can use 'B' as the format for the_date() and/or the_time() to generate Swatch Internet Time format. If you're modifying a theme, just find the references to the_date() and/or the_time() in the template files and change the value of the format parameter. If you're creating a plugin, you can hook into the get_the_date and/or get_the_time filters.


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

A very simplistic method of achieving this would be as follows; add_action('template_redirect', 'recently_read'); function recently_read(){ global $post; //only run this function for the posts post_type if ( !is_single() ) return; //get the current time in the format of: 2013-02-22 11:55:51 $timestamp = ...


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

WordPress is not written in these languages and have no assumed way to interact with them. You can access such info by connecting to WP database or by accessing WP-generated RSS feed, whatever is easier for tools you need to use.


1

You should be able to submit the following information to set a custom date $_POST['aa'] // Month $_POST['mm'] // Day $_POST['jj'] // Year $_POST['hh'] // Hour $_POST['mn'] // Minute $_POST['ss'] // Second


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

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.


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

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

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 ) < ...



Only top voted, non community-wiki answers of a minimum length are eligible