Hot answers tagged

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


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

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


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

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

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

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

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

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

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

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

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


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


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

One: Purpose of the timezone setting in the Admin -> Settings section? Two: How is the time of the blog saved? To set your local time, use the wp-admin » Settings - Timezone. As a comment there is saying: "Choose a city in the same timezone as you." For each of the blogpost there are two fields in the database: post_date and post_date_gmt. So ...


1

wp_cron operates on intervals and there is no interval that will hit exactly the first day and the 15th of every month. You could run your wp-cron job every day and check the date, similar to this but with a simple callback like: cron_callback_wpse_113675() { $date = date('d'); if ('01' == $date || '15' == $date) { // run your function } } Or, ...


1

Here is how it works for me with minor changes: global $post; $post_created = strtotime($post->post_date); $sixMonthsAgo = strtotime('-6 months'); $human_time = 'hace '. human_time_diff( get_the_time('U'), current_time('timestamp') ); $mobile = wp_is_mobile(); if ($post_created > $sixMonthsAgo && $mobile) { the_time('j. M .Y'); ...


1

It depends on what the template uses to output whatever you're trying to remove. If you look in source at whatever function is outputting what you want to remove, they each have a filter to let you modify output where you can __return_false instead, however, if there's text or markup surrounding those template tags, your only option is to modify the ...


1

It's a WP non-code programming thinking error. Under General Settings > Timezone It should be set to your own timezone.


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



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