How to sort CPT by custom meta value (date), and return posts month by month

This isn’t complete copy/paste code, but hopefully it’s understandable enough to get you started. First step is to register your post type and add a rewrite rule to handle years/months. This will give you single events at event/post-name/, your post type archive at calendar, and handle incoming requests for calendar/yyyy/mm/. Make sure to visit your … Read more

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

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)