carbon-fields icon indicating copy to clipboard operation
carbon-fields copied to clipboard

[Feature] Association Field - Search on title OR meta

Open jesperkraght opened this issue 6 years ago • 1 comments

Version

  • Carbon Fields: 3.1.14

Expected Behavior

Be able to modify the search query on the Association Field to search on the defaults s OR meta-data. Useful when searching on custom post-types or WooCommerce product (sku).

Actual Behavior

By default results are found by searching title, content or excerpt. The carbon_fields_association_field_options_{name}_{type}_{subtype} filter allows you do modify the query arguments but the relation between the defaults s and the meta_query will always be 'AND' when it really should be using 'OR'.

Comments

I've tried to achieve this in many ways, by using filters like carbon_fields_association_field_options, pre_get_posts etc, with no luck. By using pre_get_posts I successfully got it to search on title OR meta, but I was receiving a lot of duplicate posts, resulting in over 40.000 results with only 2020 actual posts.

jesperkraght avatar Feb 28 '20 13:02 jesperkraght

Hi @TheYaXxE

Apologies for the late reply!

The request you are asking for has nothing to do with Carbon Fields, but rather with the way WordPress query works.

By default, WordPress uses AND join when using s and meta_query arguments.

However, after a quick search I came up with the following StackOverflow answer, which seems to solve the issue -- https://wordpress.stackexchange.com/a/208939

Hope this helps!

jorostoyanov avatar Nov 04 '20 15:11 jorostoyanov