Problem: I would like to display a View of Post Type A and include a nested View of Post Type B. If no related Post Type B exist, do not show the Post Type A post.
Solution: Create the nested Views and apply a post relationship Query Filter to the View of post type B. Set it to be related to the current post in the loop. Apply the following custom code to filter out Post Type A where there are no related Post Type B:
add_filter('wpv_filter_query', 'jobs_with_bewerbungs_func', 101, 3); function jobs_with_bewerbungs_func($query, $view_settings, $view_id) { $views = array( 870 ); $relationship_slug = 'job-bewerbung-multis'; if ( in_array( $view_id, $views ) ) { $ids = array(); $jobs_args = array( 'post_type' => 'job', 'numberposts' => -1, ); $jobs = get_posts( $jobs_args ); foreach($jobs as $job) { $bewerbungs = toolset_get_related_posts( $job->ID, $relationship_slug, 'parent', 1000000, 0, array(), 'post_id', 'child' ); if( !is_array($bewerbungs) || count($bewerbungs) < 1 ) { array_push( $ids, $job->ID ); } } $query['post__not_in'] = isset($query['post__not_in']) ? $query['post__not_in'] : array(); $query['post__not_in'] = array_merge($query['post__not_in'], $ids ); } return $query; }
Relevant Documentation:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts
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.
Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.
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 17 Antworten, hat 2 Stimmen.
Zuletzt aktualisiert von vor 5 Jahren, 11 Monaten.
Assistiert von: Christian Cox.