Problem: I would like to create a Query Filter to show the most recent posts beginning 8 weeks ago and continuing to the present. I have used the post date filter feature to specify Weeks: PAST_ONE (8). That seemed to work well until the beginning of the new year, when the filter stopped showing posts from the previous year. So the filter only seems to work correctly when the date 8 weeks ago was in the same calendar year as today.
Solution: Remove the post date Query Filter in the view editor. Add a custom code snippet to filter by post_date using any PHPstrtotime-compatible date string:
function tssupp_recent_8_weeks($view_args, $view_settings, $view_id) { $view_ids = array( 123, 456 ); // Comma-separated list of View IDs if ( in_array($view_id, $view_ids) ) { $view_args['date_query'] = array( array( 'column' => 'post_date_gmt', 'after' => '8 weeks ago' ) ); } return $view_args; }
Change 123, 456 to be a comma-separated list of View IDs where you want to apply this date filter. If you want to filter by a different start date, change 8 weeks ago to any strotime-compatible date string representing the start date.
Relevant Documentation:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
https://www.php.net/strtotime
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)
Dieses Thema enthält 2 Antworten, hat 2 Stimmen.
Zuletzt aktualisiert von vor 4 Jahren, 10 Monaten.
Assistiert von: Christian Cox.