Skip Navigation

[Gelöst] Table with child posts

Dieser Thread wurde gelöst. Hier ist eine Beschreibung des Problems und der Lösung.

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 support ticket is created vor 5 Jahren, 11 Monaten. There's a good chance that you are reading advice that it now obsolete.

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 SteffenM1628 vor 5 Jahren, 11 Monaten.

Assistiert von: Christian Cox.

Author
Artikel
#1163953
table sort.png

hey christian,

puh i hope you didn´t have had to much work to get this code running. works totaly fine!
Thank you soooooooooo much.

I found maybe a bug or so in the nested views.
so my child view is a sortable table. but when i display the parent view and want to sort the table it doesn´t work.
You can see it under the Dashboard menu item and than choose "Bewerbungen" in the tabs.

Neue Threads, die von Christian Cox erstellt wurden und mit diesem verbunden sind, sind unten aufgeführt:

https://toolset.com/de/forums/topic/sorting-nested-tables/

#1164043

Okay, let's discuss the sorting table problem in the new ticket I just created: https://toolset.com/forums/topic/sorting-nested-tables/

#1164087

My issue is resolved now. Thank you!