Support

Account

Home Forums General Issues How do I show posts based on date field?

Helping

How do I show posts based on date field?

  • I have custom field artist_birth_date. Now I want to show artists list who have their birthday today. My date format is ‘January 6, 2019’ so I just need to compare month and day with today but I’m stuck getting this out from custom field to compare. Following is my loop code:

    <?php
    $today = date('F j');
    $args = array(
    'post_type'=> array( 'artist'),
    'posts_per_page' => '-1',
    'meta_key' => 'artist_birth_date',
    'meta_query' => array(
    array(
    'key'     => 'artist_birth_date',
    'value'   => $today,
    'compare' => '=',
    ),
    ),
    );
    $the_query = new WP_Query( $args );
    ?>
  • Any help? I just need direction on how can I compare just day and month with today.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.