Populating meta box with select-list of existing posts, and assigning it to custom post types

I believe this is what you were looking for. I moved back to using a class because what you were using would very easily conflict with someone else’s code who decided to use the function names select_box_add_meta_box(), select_box_content() and/or select_box_save_postdata(), which is reasonably likely. The class name WPSE_85107 is only likely to conflict with somebody … Read more

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

Order custom posts by a date metabox

When you’re saving the data on your custom post type you need to set it so that the meta box value is actually stored as a UNIX timestamp, eg: if(!isset($_POST[“event_informations_date”])) { return $post; } else { $event_as_timestamp = strtotime ( $_POST[“event_informations_date”]; update_post_meta($post->ID, “event_informations_date”, $event_as_timestamp ); } This way you will have an orderable value for … Read more