
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. 🙂
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

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.
Thanks a lot for your assistance. I have submitted a feature request. For now I will only allow users to select one Activity.