Ordering posts by custom field and grouped by month

<?php $period = date(“Y-m-d”); $args = array( ‘post_type’=>’event’, ‘posts_per_page’=> -1, ‘order’=> ‘DESC’, ‘orderby’=> ‘meta_value’, ‘meta_key’=>’event_start_date’ ‘meta_value’ => $period, ) $events = new WP_Query( $args ); if ($events->have_posts()) : while (have_posts()) : the_post(); the_title(); // (etc.) endwhile; endif; ?> Please follow below link for details. Link for details link for code source Thanks!

Get previous posts list

Did you chceck the Codex Date Parameters ? Expecially the ‘before’ param.It works like this: $date = get_the_date(‘Y-m-d H:i:s’); $args = array( ‘date_query’ => array( array( ‘before’ => $date ), ), ‘posts_per_page’ => 10, ); $query = new WP_Query( $args );

Convert all dates stored in custom field

Find the correct key for game_date_key and run this once: global $wpdb; $posts = $wpdb->get_results(“SELECT ID FROM “.$wpdb->prefix.”posts” WHERE post_type=”post”); foreach ($posts as $post) { $old_date = get_post_meta($post->ID,’game_date_key’,true); $new_date = date(‘d/m/Y’, strtotime($old_date)); update_post_meta($post->ID,’game_date_key’,$new_date,$old_date); } (I assume you will have the sense to backup your database first just in case. 🙂

Auto update post title and slug when post status is changed

I think I found the solution: add_filter(‘wp_insert_post_data’,’reset_post_date’,99,2); function reset_post_date($data,$postarr) { //update post time on status change $data[‘post_date’] = $data[‘post_modified’]; $data[‘post_date_gmt’] = $data[‘post_modified_gmt’]; //also update title and add the current date to title $data[‘post_title’] = ‘Your Default Title – ‘. current_time ( ‘m-d-Y’ ); //also update the slug of the post for the URL $data[‘post_name’] = … Read more

Add “Posted on” to post date

The post date is added by twentyfourteen_posted_on as shown in content.php. This function is in /inc/template-tags.php and is correctly wrapped in an if ( ! function_exists( ‘twentyfourteen_posted_on’ ) ) conditional so you can declare the same function in your child theme and modify it to your heart’s content. As such you could add a function … Read more

wordpress meta value compare between two date

After some research on wp codex I found my solution. Here I have to change birth_date format during save. I saved value like yy-mm-dd this format and changed my meta_query Here is the code $studentdata = get_users( array( ‘meta_query’=> array( array( ‘key’ => ‘birth_date’, ‘value’ => array( $startyear.’-01-01′,$endyear.’-12-31′), ‘compare’ => ‘BETWEEN’, ) ), ‘role’=>’student’ ) … Read more

Modify this line to give alternate format date?

Instead of using $post->post_date, use get_the_time( $format, $post ). The correct PHP date format string for your question is ‘d/m/y H:i’. … Assuming you want a two digit minute (even when less that 10 minutes). Also, I may have the month and day the wrong way around for you. The format argument in get_the_time() is … Read more