Problem: I would like to use a conditional to display different content based on the current User's horoscope sign, based on a User birthdate custom field.
Solution:
Inside a View of Users, to access the current logged-in User's information you must use a nested View of Users. Create a new View of Users, filtered by specific Users, using a shortcode attribute filter "users". See the attached screenshot. Use the wpv-current-user shortcode to pass the current User's ID into the nested View filter. Here is an example using your portrait View:
<wpv-loop> [wpv-view name="nested-view-slug" users="[wpv-current-user info='id']"] </wpv-loop>
Add the following custom shortcode:
add_shortcode( 'is_month_day_between', 'is_month_day_between_func'); function is_month_day_between_func($atts) { // shortcode attributes for timestamps start time, end time, and test time $start = $atts['start']; $end = $atts['end']; $test = $atts['test']; $result = 0; // make new timestamps using the current Year so we can compare $modStart = strtotime(date('d F, ', $start) . date('Y')); $modEnd = strtotime(date('d F, ', $end) . date('Y')); $modTest = strtotime(date('d F, ', $test) . date('Y')); // compare and return 0 or 1 if test is between start and end if(($modStart <= $modTest) && ($modTest <= $modEnd)){ $result = 1; } return $result; }
Register 'is_month_day_between' in Toolset > Settings > 3rd party Shortcode Arguments, then you can use it in a conditional that tests the User's birthday against a known range of dates.
[wpv-conditional if="([is_month_day_between start='1498247543' end='1440359543' test='[wpv-post-field name='wpcf-date-de-naissance']'] eq '1')"] This month and day is between start and end [/wpv-conditional] [wpv-conditional if="([is_month_day_between start='1498247543' end='1440359543' test='[wpv-post-field name='wpcf-yourdatefieldslug']'] eq '1')" evaluate="false"] This month and day is not between start and end [/wpv-conditional]
To account for the first sign, which spans two years, you must use two conditionals that test if the date is between Dec 21 and Dec 31, or if the date is between Jan 1 and Jan 21.
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.
Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | - | - |
13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | - | - |
Supporter timezone: America/New_York (GMT-04:00)
Este tema contiene 19 respuestas, tiene 3 mensajes.
Última actualización por hace 6 años, 10 meses.
Asistido por: Christian Cox.