Skip Navigation

[Resolved] Display Categories Within A View That Uses Intermediary Posts

This support ticket is created 3 years, 9 months ago. 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 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 20 replies, has 2 voices.

Last updated by chantalM 3 years, 9 months ago.

Assisted by: Minesh.

Author
Posts
#2183685

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I've adjusted the code as given under under the "Custom Code" section. I'm not sure how the original code I've added was updated. Maybe by mistake.

add_filter( 'wpv_filter_query_post_process', 'func_order_view_basedon_booking_from', 20, 3 );
function func_order_view_basedon_booking_from( $query, $view_settings, $view_id ) {
  global $wpdb;
  global $WP_Views;
  if ( in_array( $view_id, array(11832,12025 ) ) ) {
     
    if ( !empty( $query->posts ) ) { // if the query found no posts
        
      $allposts = $query->posts;
       
     
      foreach($allposts as $k=>$v):
      
      $child_id = $WP_Views->view_shortcode_attributes[0]['wpvrelatedto'];
 /*     
      $sql = $wpdb->prepare( "SELECT element_id FROM {$wpdb->prefix}toolset_connected_elements WHERE group_id in( 
       select intermediary_id from {$wpdb->prefix}toolset_associations where parent_id=(select group_id from {$wpdb->prefix}toolset_connected_elements where element_id=".$v->ID.") AND child_id=(select group_id from {$wpdb->prefix}toolset_connected_elements where element_id=".$child_id.")
       )");
      $res = $wpdb->get_results($sql, OBJECT);
*/
      
      $intermediary_id = toolset_get_related_posts(array(
                                          'parent' => $v->ID,
                                          'child' => $child_id
                                          ),
                                          'post-venue',
                                          array(
                                          'role_to_return' => 'intermediary'
                                          ));
      
       
    foreach($intermediary_id as $x=>$y):
        $date_array[$v->ID] = get_post_meta($y,'wpcf-booking-from',true);
    endforeach;
    endforeach;
       
    }
     
    // sorting the array
    asort($date_array);
     
   foreach($date_array as $k=>$v):
         foreach($allposts as $x=>$y):
                if($k==$y->ID){
                  $sorted[] = $y;
                }
            endforeach;
   endforeach;
     
    $query->posts = $sorted;
     
    }
    return $query;
}

Can you please confirm it works as expected now: hidden link

#2183687

Hi Minesh,

The View has disappeared from the page: hidden link

#2183689

It has also disappeared from your demo page: hidden link

#2183691

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

It should work OK now. Can you please confirm.

#2183715

You Sir, are amazing! Thank you Minesh!

#2183717

My issue is resolved now. Thank you!