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