Problem:
Set up a View that list date field birthday today - list all posts who has birthday today
Solution:
To display only posts to compare the custom date field which holds the birthdate and compare the birthdate with today's date, you need to add the following filter to your current theme's functions.php file.
add_filter( 'posts_where' , 'func_filter_birtdate_posts'); function func_filter_birtdate_posts( $where ) { global $WP_Views; global $wpdb; if($WP_Views->current_view == 9999){ $where .= " And ".$wpdb->prefix."posts.ID IN (SELECT post_id FROM ".$wpdb->prefix."postmeta WHERE (".$wpdb->prefix."postmeta.post_id = ".$wpdb->prefix."posts.ID) AND ".$wpdb->prefix."postmeta.meta_key = 'wpcf-data-di-nascita' AND month(FROM_UNIXTIME(".$wpdb->prefix."postmeta.meta_value)) = month(now()) AND day(FROM_UNIXTIME(".$wpdb->prefix."postmeta.meta_value)) = day(now()) )"; } return $where; }
Where:
Replace 9999 with your original view ID
You can find the proposed solution in this case with the following reply:
https://toolset.com/forums/topic/set-up-a-view-that-list-date-field-birthday/#post-1263805
Relevant Documentation:
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 |
---|---|---|---|---|---|---|
- | 10:00 – 13:00 | 10:00 – 13:00 | 10:00 – 13:00 | 10:00 – 13:00 | 10:00 – 13:00 | - |
- | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | - |
Supporter timezone: Asia/Kolkata (GMT+05:30)
This topic contains 4 replies, has 2 voices.
Last updated by 5 years, 7 months ago.
Assisted by: Minesh.