Title: Filtering multiple custom fields with WP REST API 2
Last modified: August 31, 2016

---

# Filtering multiple custom fields with WP REST API 2

 *  [sohrabtaee](https://wordpress.org/support/users/sohrabtaee/)
 * (@sohrabtaee)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/filtering-multiple-custom-fields-with-wp-rest-api-2/)
 * I want to filter posts based on multiple acf custom fields with AND relation.
   Something like this:
 *     ```
       $args = array(
               'post_type'  => 'product',
               'meta_query' => array(
                   'relation' => 'AND',
                   array(
                       'key'     => 'color',
                       'value'   => 'blue',
                       'compare' => '=',
                   ),
                   array(
                       'key'     => 'price',
                       'value'   => array( 20, 100 ),
                       'type'    => 'numeric',
                       'compare' => 'BETWEEN',
                   ),
               ),
           );
       ```
   
 * I might even have more filters. How can I convert these to REST API 2 filters?
 * [https://wordpress.org/plugins/rest-api/](https://wordpress.org/plugins/rest-api/)

Viewing 1 replies (of 1 total)

 *  [websupporter](https://wordpress.org/support/users/websupporter/)
 * (@websupporter)
 * [10 years ago](https://wordpress.org/support/topic/filtering-multiple-custom-fields-with-wp-rest-api-2/#post-7379784)
 * Hi sohrabtaee,
    sorry for the late reply. Basically speaking, custom fields are
   not available for filtering through the WordPress REST API right now, since this
   opens up some implementation and security issues depending on the data you store
   as meta data.
 * Nevertheless, you could work around by registering the WordPress Meta Query as
   a query var for the REST API:
 *     ```
       add_filter( 'rest_query_vars', 'test_query_vars' );
           function test_query_vars ( $vars ) {
               $vars[] = 'meta_query';
               return $vars;
           }
       ```
   
 * After this you could create a URL like
 *     ```
       http://local.wordpress.dev/wp-json/wp/v2/posts?filter[meta_query][0][key]=color&filter[meta_query][0][value]=blue&filter[meta_query][1][key]=price&filter[meta_query][1][value][0]=20&filter[meta_query][1][value][0]=100&filter[meta_query][1][type]=numeric&filter[meta_query][1][compare]=BETWEEN
       ```
   
 * Have also a look into this related discussion here:
    [https://github.com/WP-API/WP-API/issues/2459](https://github.com/WP-API/WP-API/issues/2459)

Viewing 1 replies (of 1 total)

The topic ‘Filtering multiple custom fields with WP REST API 2’ is closed to new
replies.

 * ![](https://ps.w.org/rest-api/assets/icon-256x256.png?rev=1346297)
 * [WordPress REST API (Version 2)](https://wordpress.org/plugins/rest-api/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/rest-api/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/rest-api/)
 * [Active Topics](https://wordpress.org/support/plugin/rest-api/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/rest-api/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/rest-api/reviews/)

## Tags

 * [WordPress REST API](https://wordpress.org/support/topic-tag/wordpress-rest-api/)

 * 1 reply
 * 2 participants
 * Last reply from: [websupporter](https://wordpress.org/support/users/websupporter/)
 * Last activity: [10 years ago](https://wordpress.org/support/topic/filtering-multiple-custom-fields-with-wp-rest-api-2/#post-7379784)
 * Status: not resolved