Navigation überspringen

[Gelöst] Displaying related child

This support ticket is created vor 1 Monat, 4 Wochen. 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 -

Zeitzone des Unterstützers: Asia/Kolkata (GMT+05:30)

Dieses Thema enthält 0 Antwort, hat 1 Stimme.

Zuletzt aktualisiert von pierre-yvesC vor 1 Monat, 2 Wochen.

Assistiert von: Minesh.

Author
Artikel
#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
versteckter Link

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

Any idea?

#2807359

Minesh
Unterstützer

Sprachen: Englisch (English )

Zeitzone: 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
Unterstützer

Sprachen: Englisch (English )

Zeitzone: 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":
=> versteckter Link

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:
=> versteckter Link

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:
- versteckter Link

#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: versteckter Link

The view : versteckter Link

Many thx

#2807920

Minesh
Unterstützer

Sprachen: Englisch (English )

Zeitzone: 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.