Problem:
I would like to add a query filter to a view that shows only posts that have a featured image.
Solution:
This can be achieved by using our views custom filters. Add this code in your theme’s or child theme’s functions.php file:
add_filter('wpv_filter_query', 'show_featured', 10, 3); function show_featured($query, $view_settings,$view_id ) { if($view_id == 999) //replace view ID { $query['meta_key'] = '_thumbnail_id'; } return $query; }
Relevant Documentation:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
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 |
---|---|---|---|---|---|---|
- | 12:00 – 17:00 | 12:00 – 17:00 | 12:00 – 17:00 | 12:00 – 17:00 | 12:00 – 17:00 | - |
- | 18:00 – 21:00 | 18:00 – 21:00 | 18:00 – 21:00 | 18:00 – 21:00 | 18:00 – 21:00 | - |
Supporter timezone: Asia/Karachi (GMT+05:00)