Skip Navigation

[Resolved] Displaying a list of users that have an upcoming birthday

This support ticket is created 3 years, 11 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 7 replies, has 3 voices.

Last updated by jeffreyS-6 3 years, 11 months ago.

Assisted by: Shane.

Author
Posts
#1615671

Tell us what you are trying to do?
I am trying to display a list of users with upcoming birthdays. I tried following the information in this post https://toolset.com/forums/topic/get-posts-by-a-specific-custom-meta-date/ but I get an error: Warning: date() expects parameter 2 to be int, string given in /functions.php on line 56.

I have a custom field wpcf-date-of-birth and would like to query a view to display the next 10-15 users who have a birthday that is greater than or equal to today.

What is the link to your site?
bristolhome.org

#1615933

I tried following the information in this post https://toolset.com/forums/topic/get-posts-by-a-specific-custom-meta-date/ but I get an error: Warning: date() expects parameter 2 to be int, string given in /functions.php on line 56.
Hello, for one thing this code assumes the date field will never be empty. If an empty field is possible, your custom code would need to handle that case. However, I don't really see how it's relevant in your case if what you really want is to query posts by custom field as a birthday, as stated below.

I have a custom field wpcf-date-of-birth and would like to query a view to display the next 10-15 users who have a birthday that is greater than or equal to today.
There's really not a simple way to set up this kind of query with Views. Types stores dates using a Unix timestamp format, like 1588885735 for May 7 2020, 21:08:55 GMT. Therefore the sorting mechanism for the query isn't straightforward:
The timestamp for May 10 1979 is
295191832
The timestamp for May 11 1950 is
-619956968
The timestamp for May 11 1999 is
926430232
So as you can see simply sorting as integer or string here will fail. Those are the two main algorithms Views can implement. Distance is a third. You need a different algorithm to convert these integer timestamp values to some other format that can be compared effectively, like a custom SQL query. Unfortunately this type of direct database query falls outside the scope of support we provide here in the forums so I don't have a simple cut-and-paste solution for you - I can only offer some general advice. To implement a custom SQL query, you'll need to use the WordPress wpdb class:
https://developer.wordpress.org/reference/classes/wpdb/

Here's a related ticket with a similar requirement, where the client shared a solution that worked for their site:
https://toolset.com/forums/topic/get-next-3-upcoming-birthday/

Note that their solution is specifically designed to check Users, not custom post types, so if your dates are associated with a custom post type instead of Users you'll have to query postmeta instead of usermeta.

#1623067

Hi Christian,

I decided to just add custom fields for the birthdays. One for month and one for day. I did the same thing with work anniversaries. I created a view for each and put them on a page. I am filtering them by month using a url Variable. Now it works well and pulls the users in a list for the current month but I am having duplicates display for certain users. If you look at December using this url hidden link you will see Carla shows up three times in Work Anniversaires. If you look at September using this link hidden link you will see Aimee shows up twice in Birthdays. Why am I getting duplicates for certain users and not others. How can I prevent this?

#1624471

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Jeffery,

As Christian is currently unavailable I will be handling his tickets for him.

Taking a look at this it may be that you have the posts itself duplicated, However I would need to look at the view itself to see exactly what is happening.

Would you mind allowing me to have admin access to the website so that I can have a look ?

Thanks,
SHane

#1624861

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Jeffery,

I found that when I added the shortcode to display the view data directly to the Loop output editor there are no repeats.

Can you try deleting this template and recreate it and see if the issue still remains.

It seems the template of this view is causing the items to repeat.

Thanks,
Shane

#1624871

Hi Shane!

Thank you!!! I just pulled used some div tags and styles in the loop and it appears to fix the issue. I just tested it with the birthdays and it is working. I will do the same with the anniversaries.

I appreciate your help!

Jeff

#1624893

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Jeff,

Happy I was able to help you on this one.

You can go ahead and mark this one as resolved if there are no further issues on this.

Thanks,
Shane

#1625661

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.