Support

Account

Home Forums General Issues Display Upcoming Birthdays using Date Picker Field

Unread

Display Upcoming Birthdays using Date Picker Field

  • I’m creating an internal employee portal and selecting an employee’s birth month and day (the year isn’t being shown and isn’t set according to the actual birth year). I’m wanting to create an “Upcoming Birthdays” area that shows either the current month’s birthdays or upcoming birthdays within the next 30 days. At this point, it’s whatever is easiest, I don’t care.

    I’ve used/modified code from these threads with no luck: https://support.advancedcustomfields.com/forums/topic/filter-posts-by-just-month-and-year-values-from-datepicker-custom-field/ -and- https://support.advancedcustomfields.com/forums/topic/how-do-i-only-show-future-events/

    Using one of these options, I found a solution to show all birthdays from now through December, but because it factors in the year, it doesn’t loop back through Jan-Dec for the following year, if that makes sense.

    I want to filter by month and date and completely ignore the year.

    This is the closest I’ve come to a solution but it lists out all birthdays:

    <?php
        $children = get_children( array( 
            'post_parent' => 49425, 
            'post_type' => 'page', 
            'meta_key' => 'employee_birthday',
            'meta_compare' => '>=',
            'meta_type' => 'date',
            'meta_value' => array ($date_1, $date_2),
            'orderby' => 'meta_value_num',
            'order' => 'ASC',
            'posts_per_page' => 5
            ) );
        if ( $children ) {
            foreach( $children as $child ) { ?>
                <div class="u-md-3 u-sm-6 pad-right pad-left">
                    <img class="primary-photo" src="<?php the_field( 'employee_photo', $child->ID ); ?>" onmouseover="this.src='<?php the_field( 'alternate_photo', $child->ID ); ?>'" onmouseout="this.src='<?php the_field( 'employee_photo', $child->ID ); ?>'" />
                    <p><a href="<?php echo get_permalink( $child->ID ); ?>"><?php the_field('employee_first_name', $child->ID); ?> <?php the_field('employee_last_name', $child->ID); ?></a></p>
                    <p><?php the_field('employee_birthday', $child->ID); ?></p>
                </div>
        <?php } } ?>

    Thank you for any help!

Viewing 1 post (of 1 total)

The topic ‘Display Upcoming Birthdays using Date Picker Field’ is closed to new replies.