Passer la navigation

[Résolu] Displaying related child

This support ticket is created Il y a 1 mois et 3 semaines. 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Fuseau horaire du supporter : Asia/Kolkata (GMT+05:30)

Ce sujet contient 0 réponse, a 1 voix.

Dernière mise à jour par pierre-yvesC Il y a 1 mois et 2 semaines.

Assisté par: Minesh.

Auteur
Publications
#2807251

A few weeks ago Toolset crew helped me with this one https://toolset.com/forums/topic/filtering-parent-with-child-taxonomy/

It worked great, many thx.

This was intended to display related child within a view that displays child.

The problem I have, is that each child are displayed, creating doublons.

On my test site, you can see the parent posts (organisations) are display many times. For example, Efficient garage is there twice, Nice bank 3 times, etc
lien caché

I'm trying to limit it to 1 but I can't figure how.

Any idea?

#2807359

Minesh
Supporter

Les langues: Anglais (English )

Fuseau horaire: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

There is no way in that format. I mean then you will have to change the format.

Then you will have to display:
- Parent post 1
-- related child post 1
-- related child post 2
- Parent post 2
-- related child post 3
-- related child post 4

If you can share admin access details I will create a test page and display the content as per your requirement and later on you can format it as per your requirement but before that I will have to review your current structure.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2807480

Minesh
Supporter

Les langues: Anglais (English )

Fuseau horaire: Asia/Kolkata (GMT+05:30)

I've added the following code to "Custom Code" section offered by Toolset with the code snippet namely "toolset-custom-code":
=> lien caché

add_shortcode('heading', 'my_heading');
   
function my_heading($atts, $content = '') {
  static $organization_name = null;
 
  $condition = $atts['condition'];
  $value = $atts['value'];;
  
  switch ($condition) {
    case 'organization_name':
  
      if ($$condition != $value) {
        $$condition = $value;
        return $content;
      }
      break;
  }
  return '';
}


add_filter( 'wpv_filter_query_post_process', 'func_group_by_parent_post', 999, 3 );
function func_group_by_parent_post( $query, $view_settings, $view_id ) {
    
    if ($view_id == 993) { 
     
    $group_by_parent = array();
    $relationship_slug = 'organisation-job';
      
    if ( !empty( $query->posts ) ) {
           
               $all_posts = $query->posts;
      
      		
      
            foreach($all_posts as $k=>$v):
                 
       		    $parent_id =  toolset_get_related_post($v->ID,$relationship_slug);
           		$group_by_parent[$parent_id][] = $v;
       
      		endforeach;
     		
      
      		 foreach($group_by_parent as $k=>$ordered_posts):
                 foreach($ordered_posts as $k=>$v):
       		    	$final_result[] =  $v;
           
       			endforeach;
      		endforeach;
    
 
      		 $query->posts = array_values($final_result); 
             $query->found_posts = count($final_result); 
             $query->post_count =  count($final_result); 
                
    }        
  }
 
    return $query;
}

I've created the following test view:
=> lien caché

To display the organiation only once, I've added the heading shortcode:

<wpv-loop>
          [heading condition="organization_name" value="[wpv-post-title item='@organisation-job.parent']"]
      <h4>[wpv-post-title item='@organisation-job.parent']</h4>
[/heading]
          
 
          
          <li>[wpv-post-link]</li>
		</wpv-loop>

Can you please confirm it works as expected:
- lien caché

#2807521

Hi Minesh,

That's pretty cool! Bad I couldn't make it by myself.

It works exactly how I wish, except I'm unable to make it work in a 3 columns view.

The page: lien caché

The view : lien caché

Many thx

#2807920

Minesh
Supporter

Les langues: Anglais (English )

Fuseau horaire: Asia/Kolkata (GMT+05:30)

I checked but due to the complex structure and grouping there is no way to list three columns but you can display the results as normal list instead.

#2808074

OK, thx for your work. Truly appreciated.