Problem: I would like to show a View on my site only on specific days of the week. The View should only appear Monday - Thursday.
Solution:
There is no built-in way to accomplish this, but you can use a custom shortcode to return the day of the week and test that value in a conditional. Add this code to functions.php:
add_shortcode( 'format_today', 'format_today_func'); function format_today_func($atts = []) { $atts = shortcode_atts([ 'format' => 'l', ], $atts); $today = date($atts['format']); return $today; }
Then go to Toolset > Settings > Frontend Content > Third-party shortcode arguments and add format_today.
The full conditional:
[wpv-conditional if="( '[format_today]' eq 'Friday' ) OR ( '[format_today]' eq 'Saturday' ) OR ( '[format_today]' eq 'Sunday' )" evaluate="false"] View goes here and is shown Monday - Thursday only. [/wpv-conditional]
Relevant Documentation:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/
https://codex.wordpress.org/Shortcode_API
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 |
---|---|---|---|---|---|---|
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)
This topic contains 2 replies, has 2 voices.
Last updated by 6 years, 6 months ago.
Assisted by: Christian Cox.