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

can you set a default value to a custom field

You can check it by adding a hook to save_post action. In this way all your posts will have default value for a custom field. add_action( ‘save_post’, ‘wpse8170_save_post’, 10, 2 ); function wpse8170_save_post( $post_id, WP_Post $post ) { if ( ( defined( ‘DOING_AUTOSAVE’ ) && DOING_AUTOSAVE ) || !current_user_can( ‘edit_post’ ) ) { return; } … Read more

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