Skip Navigation

[Resolved] View query filter gets added to another field

This support ticket is created 2 years, 10 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 18 replies, has 2 voices.

Last updated by Arno 2 years, 9 months ago.

Assisted by: Minesh.

Author
Posts
#2358965

Minesh
Supporter

Languages: English (English )

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

Could you please check now: hidden link

I've added the following view filter to the "Custom code" section offered by Toolset within the code snippet "toolset-cutom-code":
=> hidden link

add_filter( 'wpv_filter_query', 'func_filter_by_intermediary_custom_field',99 ,3 );
function func_filter_by_intermediary_custom_field( $query_args,$views_settings, $view_id) {
  global $post;

  $views = array( 2107 ); 
  
 
  if ( in_array( $view_id, $views ) ){
    
    
    $related_ids = array();
     if(isset($_POST['search']['dps_general'])){
        foreach($_POST['search']['dps_general'] as $k=>$v):
            if($v['name'] == 'wpv-relationship-filter[]'){
              $related_ids[] = $v['value'];
            } 
              
        endforeach;
   }
    
  
    
   if(!empty($related_ids)) {
     
     foreach( $related_ids as $k=>$v):
    	$localities_ids[] = toolset_get_related_posts(
                                     $v,
                                     'travel-ticket-activity-included-relation',
                                      'child',
                                      999,
                                       0,
                                       array(),
                                      'post_id',
                                      'parent'
                                      );
    
    endforeach;
    
    	$result = array();
        $first = $localities_ids[0];
      	for($i=1; $i<count($localities_ids); $i++){
       		$result = array_intersect ($first, $localities_ids[$i]);
       		$first = $result;
      	}
		unset($query_args['pr_filter_post__in']);
    	$query_args['post__in'] = array_values($result);
     
   }
    
  }
  return $query_args;
}

Could you please confirm it works as expected, it was a challenging task but happy to see that we finally have the solution you were aiming since last week. 🙂

#2359021

Hi Minesh,

Thanks a lot, again! This gives the expected result if selecting all activities. If the user selects one activity it outputs too many tickets (e.g. if selecting City Walk it should only output 1 ticket, not 3).

Perhaps I should stick to basic Toolset functionality here as well. In this case that means we should only allow the user to select one activity at the time, not multiple. A feature request may make sense, as I can imagine more use cases with filtering on ALL related posts that must match, rather than ANY.

Can I safely rename your code snippet? There's no reference to it from anywhere, right?

Yes, all of this is quite a challenge 🙂 Your help is greatly appreciated.

Thanks,
Arno

#2359077

Minesh
Supporter

Languages: English (English )

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

Yes you just disable the code snippet (deactivate it) and you can set to use the single select activity as a time.

#2359105

Thanks a lot for your assistance. I have submitted a feature request. For now I will only allow users to select one Activity.