这是我在契约中找到的代码,请帮助我,因为我是wordpress的新手
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' => 'biography',
'meta_key' => 'date_of_birth',
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'date_of_birth',
'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)&#34; birth_date&#34;是应该在帖子下创建的元字段的关键。
2)当前日期和存储日期的格式应相同。