[Resolved] Displaying a list of users that have an upcoming birthday
This support ticket is created 4 years, 6 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.
No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.
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.
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/
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.
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?
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 ?
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.