Problem: I would like to display a list of posts that were published in the last 2 months, but I can't get the Query Filter to work correctly.
Solution: Month range filters like this aren't simple to add in wp-admin but I can provide a custom code snippet that will help. First, please remove the post date filters from your View. Then add the following code to your child theme's functions.php file, or create a new snippet in Toolset > Settings > Custom code:
add_filter( 'wpv_filter_query', 'get_past_two_months_posts', 10, 3); function get_past_two_months_posts( $query_args ,$view_settings, $view_id ) { $views = array( 12345 ); if (in_array($view_id, $views)) { $query_args['date_query'] = array( 'column' => 'post_date', 'after' => '2 months ago', ); } return $query_args; }
Replace 12345 with the numeric ID of this View.
Relevant Documentation:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
https://codex.wordpress.org/Class_Reference/WP_Query#Date_Parameters
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, 1 month ago.
Assisted by: Christian Cox.