CarrieI2136
Support threads created in the last 30 days: 0
Favorite Forum Topics
This user has no favorite topics.
Forum Topics Created
Status | Topic | Supporter | Voices | Posts | Freshness |
---|---|---|---|---|---|
Tabs show on single page but not home
Started by: CarrieI2136 in: Toolset Professional Support |
2 | 8 | 6 years, 10 months ago | ||
Filtering results by current day of the week, not date
Started by: CarrieI2136
in: Toolset Professional Support
Problem: I have a taxonomy that includes terms for each day of the week. I would like to filter posts in a View using the current day of the week, so that only posts tagged with the term for today are shown. Solution: Taxonomy term filters do not allow any date criteria in wp-admin, so custom code is required. Assuming the term slugs are "monday", "tuesday", and so on through "sunday", add the following code in your child theme's functions.php file to filter a View by term based on the local current day of the week: add_filter( 'wpv_filter_query', 'only_todays_posts',99,3 ); function only_todays_posts( $query_args,$views_settings, $view_id) { if ($view_id == 12345){ $query_args = array( 'tax_query' => array( array( 'taxonomy' => 'day-of-the-week', 'field' => 'slug', 'terms' => strtolower(date('l')), 'operator' => 'IN' ), ), ); } return $query_args; } Replace 12345 with the numeric ID of your View, and replace day-of-the-week with the slug of your custom taxonomy. Nothing extra is needed in wp-admin. Relevant Documentation: https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query |
2 | 3 | 6 years, 10 months ago |