Title: Possible bug when querying multiple Advanced Custom Fields?
Last modified: August 21, 2016

---

# Possible bug when querying multiple Advanced Custom Fields?

 *  [Igneosaur](https://wordpress.org/support/users/igneosaur/)
 * (@igneosaur)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/possible-bug-when-querying-multiple-advanced-custom-fields/)
 * So I’m just trying to create an OR query on multiple Custom Fields, I have followed
   the documentation both on the [WordPress docs](http://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters)
   and [the ACF docs](http://www.advancedcustomfields.com/resources/how-to/how-to-query-posts-filtered-by-custom-field-values/#example-3)
   but the query seems broken, almost like it is attempting an ‘AND’ rather than
   an ‘OR’.
 * Here’s the code I’ve got:
 *     ```
       $args = array(
           'post_type' => 'post',
           'meta_query' => array(
               'relation' => 'OR',
               array(
                   'key' => 'description',
                   'value' => $searchTerm,
                   'compare' => 'LIKE'
               ),
               array(
                   'key' => 'title',
                   'value' => $searchTerm,
                   'compare' => 'LIKE'
           ),
       );
       ```
   
 * There are the args I’m putting into WP_Query(); It doesn’t work. If I change 
   it to querying a single field (just the description) it works fine:
 *     ```
       $args = array(
           'post_type' => 'post',
           'meta_query' => array(
           array(
               'key' => 'description',
               'value' => $searchTerm,
               'compare' => 'LIKE'
           )
       );
       ```
   
 * Since it’s an ‘OR’ and it seems the code is right it should come back with the
   same results, but it comes back with incorrect results. It is like an ‘AND’ comparison.
 * I’ll explain the results:
    Let’s say I’m querying the word ‘horatio’. There are
   two records; record 1 has ‘horatio’ both in the title and the description, record
   2 just has that string in the description.
 * If I do the query on just the ‘title’ field I get back record 1 (expected). If
   I do the query on just the ‘description’ I get back both records 1 and 2 (expected),
   but if I do the query on both fields I just get record 1 (I expect to get both,
   with an OR statement).
 * Unfortunately I am running some pretty old versions of WordPress (3.1) and Advanced
   Custom Fields (2.1.4), I cannot do anything about this at the moment.
 * I have spoken to the support team at ACF and they don’t see anything wrong with
   my query.
 * Is this a bug, or am I doing something terribly wrong?

The topic ‘Possible bug when querying multiple Advanced Custom Fields?’ is closed
to new replies.

## Tags

 * [acl](https://wordpress.org/support/topic-tag/acl/)
 * [custom fields](https://wordpress.org/support/topic-tag/custom-fields/)
 * [wp_query](https://wordpress.org/support/topic-tag/wp_query/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [Igneosaur](https://wordpress.org/support/users/igneosaur/)
 * Last activity: [12 years, 5 months ago](https://wordpress.org/support/topic/possible-bug-when-querying-multiple-advanced-custom-fields/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
