Order by custom field date with ASC order

With some more googling: <?php $today = date(“Y/m/j”); query_posts(array( ‘post_type’ => ‘custompost’, ‘posts_per_page’ => 4, ‘meta_key’ => ‘mydate’, ‘orderby’ => ‘meta_value’, ‘order’ => ‘ASC’, ‘meta_query’ => array( array( ‘key’ => ‘mydate’, ‘meta-value’ => $value, ‘value’ => $today, ‘compare’ => ‘>=’, ‘type’ => ‘CHAR’ ) ) )); if (have_posts()) : while (have_posts()) : the_post(); ?> <a … Read more

Query date in wordpress loop

You want to query for posts with event_date in the future but you have saved (or so it seems from a comment), your dates as: date(“F”, $unixtime).” “.date(“d”, $unixtime).”, “.date(“Y”, $unixtime); That is “textual month name” + “numeric day” + “numeric year”. There is no way to query/sort that format so that it matches a … Read more

How to display lastest post date in the homepage?

I would save an option on post save: add_action( ‘save_post’, function($id,$p) { if ( (defined(‘DOING_AUTOSAVE’) && DOING_AUTOSAVE) || (defined(‘DOING_AJAX’) && DOING_AJAX) || ($p->post_status === ‘auto-draft’) ) { return; } update_option(‘_last_site_update’,$p->post_date); }, 1,2 ); And retrieve it with a variant of the function provided by @G-M : function my_last_updated( $format=”” ) { $last = get_option(‘_last_site_update’); if … Read more

Update existing post dates to random dates

Question How to change the post date to a randomly generated date? Answer This is fairly straightforward. What I did was to create a plugin that upon activation get all the posts, loops through them, generates a random date, and updates the post with that date. <?php /** * Plugin Name: WPSE 259750 Random Dates … Read more

Date comparison : which date format?

The date format for entering the date is largely irrelevant. strtotime will convert a lot of different formats to UNIX time. Just make sure your input format makes sense to your users and make sure that your feed strtottime a format that correctly converts to UNIX time. If you are storing data in the *_postmeta … Read more

Order by custom field date?

There are similar posts on this site about the same topic, if you look around. But here is your answer: To make this work you need to change your date format. You can sort alphabetically, or numerically, not calender-merically. The only human date format that orders correctly is YYYY/MM/DD. The separator are optional and shouldn’t … Read more

Add 20yrs to post date, and then query

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 … Read more

SQL query to update post_date (one post = one single date & time)

I would not do this with SQL. A relatively simple PHP loop should work. function bulk_schedule_posts_wpse_105834() { $args = ( array( ‘cat’ => 1, ‘posts_per_page’ => -1, ‘post_status’ => ‘draft’, ‘post_type’ => ‘post’, ) ); $posts = new WP_Query($args); if (!$posts->have_posts()) return false; $date=”2013-08-01″; $times = array( ’10:00′, ’14:00′, ’17:00′, ’20:30′ ); while ($posts->have_posts()) { … Read more