Skip Navigation

[Escalated to 2nd Tier] Custom field filter with OR in the fields relationship is applied as AND

This support ticket is created 4 years, 6 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
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Tagged: 

This topic contains 6 replies, has 2 voices.

Last updated by Shane 4 years, 6 months ago.

Assisted by: Shane.

Author
Posts
#1710461

Ana
Screen Shot 2020-07-17 at 17.27.08.png
Screen Shot 2020-07-17 at 17.26.57.png

I have the following setup:
A View that will list a Custom Post Type and a filter based on two custom post fields on which I'm using an OR for the fields relationship.

-> when using the View on the front-end and doing a search the result is that the OR condition for the custom post fields is changed to an AND.
Basically it will only display results if the search string exists on both custom fields.

I would expect that the set Fields relationship on the search filter would be honoured and not replaced.

#1710579

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Ana,

Thank you for getting in touch.

Not sure why you are using the same url parameter for the 2 different custom fields but you will need to change one of the field url parameter to something else.

The search could be getting confused as to which field it should filter by with the URL parameter.

So delete one of your fields from the search and then re-insert it.
Thanks,
Shane

#1710707

Ana
Screen Shot 2020-07-17 at 23.19.17.png
Screen Shot 2020-07-17 at 23.17.56.png
Screen Shot 2020-07-17 at 23.17.18.png

Hello Shane, thank you for your suggestion however that is not what is causing this problem, I have the same issue with different url parameters.

I have prepared a simple WordPress installation with Types and Views and having the following setup:
* create a CPT
* create a custom post field group
* add two fields of type single line
* create a View to list the CPT with a filter by these two fields with the OR field relationship
* add some data to the CPT and custom fields
* create a page for the View
* check the filter
-> the OR is not applied and we have the AND default on the SQL query (checked in debug mode for Views)

I can send you this duplicator package if you enable the field to do so on the next reply.
This is the sql generated by the View:

SELECT   wp_posts.* FROM wp_posts  INNER JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id )  INNER JOIN wp_postmeta AS mt1 ON ( wp_posts.ID = mt1.post_id ) WHERE 1=1  AND wp_posts.ID NOT IN (9) AND ( 
  ( wp_postmeta.meta_key = 'wpcf-field-name' AND wp_postmeta.meta_value LIKE '{f2c7604d0c2a5552f219464fad6f719bb2eb3d8590967190190f8dab2dce6fa5}John{f2c7604d0c2a5552f219464fad6f719bb2eb3d8590967190190f8dab2dce6fa5}' ) 
  AND 
  ( mt1.meta_key = 'wpcf-field-other-name' AND mt1.meta_value LIKE '{f2c7604d0c2a5552f219464fad6f719bb2eb3d8590967190190f8dab2dce6fa5}Steve{f2c7604d0c2a5552f219464fad6f719bb2eb3d8590967190190f8dab2dce6fa5}' )
) AND wp_posts.post_type = 'my-post' AND ((wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private')) GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC 
#1712955

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Ana,

Thank you for the screenshots. I see what you mean now.

Yes please send me the duplicator package so that I can test this here locally to see what I can find.

The private fields have been enabled for your next response.

Thanks,
Shane

#1713737

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Ana,

Thanks I was able to verify the issue and escalated it to our 2nd tier supporters.

#1721485

Ana

Hello Shane, any news here about this issue?
WordPress queries allow for having "OR" conditions when querying multiple meta fields. I was expecting that the relationship option in Views would work the same. And in fact, be used as it was selected on the resulting SQL query to filter results on the front-end resulting View.

Let me know the status of this and if there is any feedback from the 2nd tier supporters. Thanks in advance.

#1721845

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Ana,

This had worked as intended in previous versions.

Our developers have been made aware of the issue however I cannot say when a fix will be provided for this.

Thanks,
Shane