Sauter la navigation

[Résolu] Table with child posts

Ce fil est résolu. Voici une description du problème et la solution proposée.

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 Il y a 6 années et 2 mois. 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.

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)

Ce sujet contient 17 réponses, a 2 voix.

Dernière mise à jour par SteffenM1628 Il y a 6 années et 1 mois.

Assisté par: Christian Cox.

Auteur
Publications
#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.

Les nouveaux fils créés par Christian Cox et associés à celui-ci sont repris ci-dessous :

https://toolset.com/fr/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!