Skip Navigation

[Resolved] Parametric search does not fully use "AND" as fields relationship mode.

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

Last updated by KonstantinS88 5 years, 4 months ago.

Assisted by: Minesh.

Author
Posts
#1302679
wrong.JPG
filters.JPG

I have 4 custom fields set up for my custom post type. Two as drodowns and others as checkboxes. The more the user selects the less search results should come up. So I have set up "AND" as the field relationship.

Though it works between custom fields it does NOT work within the custom fields with checkboxes where you can select multiple values. Whenever I select multiple checkboxes in one custom field it does not show "those posts that have both values checked" but it will show "those that have at least one of those two checked".

This seems like bug. because I clearly have set up AND and not OR as the comparison value. What can I do?

Please see my attached visualisation and my filter settings. The red "OR"s should also be "AND"s.

Thanks a lot in advance. 🙂

#1302723

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Can you please share problem URL and access details where I can see the issue?

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) 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.

#1302771

Minesh
Supporter

Languages: English (English )

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

I've added the following code to "Custom Code" section offered by Toolset to replalce the "OR" with "AND":
=> hidden link

add_filter( 'posts_where' , 'func_custom_posts_where' );
function func_custom_posts_where( $where ) {

	if( !is_admin() ) {
		global $WP_Views;
      if($WP_Views->current_view == 8365){ 
	    $where = str_replace(" OR "," AND ",$where);
      }
		
		
	}
	return $where;
}

More info:
=> https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/

#1302783

Thanks alot for your support.

But if you activate "OEKO TEX" and then "Fairtrade" th epost "Bandana" still shows up though "Fairtrade" is not an active attribute of this post.

#1302805

Minesh
Supporter

Languages: English (English )

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

Ok - I see. I've added the following code to the "Custom Code" section using view's filter:

add_filter( 'wpv_filter_query', 'func_change_or_caluse', 101, 3 );
function func_change_or_caluse( $view_args, $view_settings, $view_id ){
 
    if ($view_id == 8365 ) { 
       
      if(count($view_args['meta_query']) > 0) {
        		foreach((array)$view_args['meta_query'] as $k=>$v):
           			           
           			if(isset($v['relation'])) {
                      $view_args['meta_query'][$k]['relation'] = 'AND';
                    }
            endforeach;
        }
    }
 
    return $view_args;
}

More info:
=> https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

Can you please confirm now it works as expected.

#1302807

Thank you very much. This fixed the issue. But should this not be the default behavior if I have set up "AND" in the views filter settings?

Thanks a lot for your quick and professional support 🙂