Problem: I have a View that shows child posts based on several filter criteria. I would also like to add a filter that only shows child posts whose parent post is published.
Solution: Use wpv_filter_query to check each parent post's status, and build a list of post IDs to define the query's 'post__in' array.
add_filter('wpv_filter_query', 'filter_children_by_parent_markt_published_func', 101, 3); function filter_children_by_parent_markt_published_func($query, $view_settings, $view_id) { if ( $view_id == 377) { global $wpdb; $ids = array(); $metas = $wpdb->get_results( "SELECT meta_value,post_id FROM wp_postmeta WHERE meta_key = '_wpcf_belongs_markt_id'" ); foreach($metas as $id) { if(isset($id->meta_value) && get_post_status($id->meta_value) == 'publish') { $ids[] = $id->post_id; } } $query['post__in'] = isset($query['post__in']) ? array_intersect($query['post__in'],$ids) : $ids; } return $query; }
Relevant Documentation: https://toolset.com/documentation/user-guides/views-shortcodes/#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 |
---|---|---|---|---|---|---|
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 7 years, 3 months ago.
Assisted by: Christian Cox.