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


5

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: define('...


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


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

This is not a WordPress question, but to help you out: function displaydate() { return date( 'd/m/Y G:i', strtotime( '-6 hours' ) ); } add_shortcode('date', 'displaydate'); The shortcode itself should work fine.


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

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


3

Wordpress has a built-in funtion called human_time_diff() that allows you to do this. Just place this code in your functions.php function time_ago( $type = 'post' ) { $d = 'comment' == $type ? 'get_comment_time' : 'get_post_time'; return human_time_diff($d('U'), current_time('timestamp')) . " " . __('ago'); } To use it anywhere in your theme (...


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

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


3

Here are some options on how we can override the native layout for each comment: Approach #1 - Overriding start_el() with a custom walker Let's define our custom wpse comment format: // Arguments for wp_list_comments() $args = [ 'style' => 'ol', 'format' => 'html5', 'short_ping' => true, ]; // Use our custom walker if it'...


2

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


2

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.


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 strval(round(($...


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

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

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


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

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.


2

Before Wordpress 4.1, you can show the date archive page titles with the following code: (Taken and slightly modified from the twentyfourteen theme) if ( is_day() ) { printf( __( 'Daily Archives: %s', 'twentyfourteen' ), get_the_date() ); } elseif ( is_month() ) { printf( __( 'Monthly Archives: %s', 'twentyfourteen' ), get_the_date( _x( 'F Y', '...


2

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 not a real cronjob, and depends on your site being called....


2

You should use date_i18n(): $timestamp = get_post_meta($post_to_edit->ID, '_single_date', true); $friendly_date = date_i18n( get_option('date_format'), $timestamp ); ?><input value="<?= $friendly_date ?>" name="_single_date" />


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

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



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