I am developing a blog website and it is a biography directory, how can i get posts for specific birth date and can fetch post for today's birth date. for example:on the date 17 may want to Show post for Biography those born on 17 may. and on the date of 18 may Show post for Biography those born on 18 may. I have attached an image and also linked a website with similar featured, i will like to know how to do this. http://frostsnow.com/
What you can do is create a meta field under a post and store birth date in that field. Now you need meta_query in you post to retrieve the current date posts.
<?php $currentDate = current_time( 'Y-m-d' ); $args = array( 'post_type' => 'my_custom_post_type', 'meta_key' => 'birth_date', 'order' => 'ASC', 'meta_query' => array( array( 'key' => 'birth_date', 'value' => $currentDate, 'compare' => 'IN', ), ), ); $query = new WP_Query( $args ); if ( $query ->have_posts() ) : ?> <!-- the loop --> <?php while ( $query ->have_posts() ) : $query ->the_post(); ?> <h2><?php the_title(); ?></h2> <?php endwhile; ?> <!-- end of the loop --> <?php wp_reset_postdata(); ?> <?php else : ?> <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p> <?php endif; ?>
1) "birth_date" is the key of the meta field that should be created under the post.
2) Format of current date and stored date should be same.