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

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

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

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


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

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

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

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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



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