Get users based on month ACF datepicker field

Question

I have an ACF field ‘date_of_birth’ which stores the user’s birthday, examples: 20201226, 20151225, 19980701

Goal: get all users which have their birthday this month, or next month.

I currently have this:

    $users_start_date_boundary = gmdate( 'Ymd', strtotime( '-1 month' ) );
    $users_end_date_boundary   = gmdate( 'Ymd', strtotime( '+2 month' ) );

    $wp_user_query = new WP_User_Query(
        [
            'fields'     => 'all_with_meta',
            'orderby'    => 'date_of_birth',
            'order'      => 'ASC',
            'meta_query' => [
                [
                    'key'     => 'date_of_birth',
                    'value'   => [ $users_start_date_boundary, $users_end_date_boundary ],
                    'compare' => 'BETWEEN',
                    'type'    => 'DATE',
                ],
            ],
        ]
    );

    return $wp_user_query->get_results();

The problem with this however, that it only gets users with a birthyear of 2020.

How do I get all users, based on the given month boundaries, while ignoring the year/day the person is born in?

0
fanatic21221 2 months 0 Answers 14 views 0

Leave an answer