Title: Multiple Filter Too Slow
Last modified: August 31, 2016

---

# Multiple Filter Too Slow

 *  [burhansalt](https://wordpress.org/support/users/burhansalt/)
 * (@burhansalt)
 * [9 years, 12 months ago](https://wordpress.org/support/topic/multiple-filter-too-slow/)
 * Hello,
 * I have custom post type with field like this:
    home_club, away_club, is_finish.
 * And I have problem when create head to head player, my filter too slow filter
   this:
    `Select all mypost type where (home_club == "A" AND away_club == "B" AND
   is_finish == TRUE ) OR (home_club = "B" and away_club = "A" and is_finish = "
   TRUE")`
 * And my Code this:
 *     ```
       <?php
                                         $type = 'match';
                                         $args = array(
                                             'post_type' => $type,
                                             'posts_per_page' => '5',
                                             'post_status' => 'publish',
                                             'meta_query' => array(
                                                 array(
                                                     'relation' => 'AND',
                                                     array(
                                                         'key' => 'home_club',
                                                         'value' => $home[1],
                                                         'compare' => '='
                                                     ),
                                                     array(
                                                         'key' => 'club_away',
                                                         'value' => $away[1],
                                                         'compare' => '='
                                                     ), array(
                                                         'key' => 'is_finish',
                                                         'value' => true,
                                                         'compare' => '='
                                                     )
                                                 ),
                                                 'relation' => 'OR',
                                                 array(
                                                     'relation' => 'AND',
                                                     array(
                                                         'key' => 'home_club',
                                                         'value' => $away[1],
                                                         'compare' => '='
                                                     ),
                                                     array(
                                                         'key' => 'club_away',
                                                         'value' => $home[1],
                                                         'compare' => '='
                                                     ), array(
                                                         'key' => 'is_finish',
                                                         'value' => true,
                                                         'compare' => '='
                                                     )
                                                 ),
                                             ),
                                             'orderby' => 'meta_value_num',
                                             'meta_key' => 'tanggal_main',
                                             'order' => 'desc',
                                         );
       ```
   

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [Aubrey Portwood](https://wordpress.org/support/users/aubreypwd/)
 * (@aubreypwd)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/multiple-filter-too-slow/#post-7382337)
 * I’m not sure what you mean by too slow?
 *  [Jay](https://wordpress.org/support/users/phyrax/)
 * (@phyrax)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/multiple-filter-too-slow/#post-7382338)
 * [@burhansalt](https://wordpress.org/support/users/burhansalt/) – Meta and Term
   queries are inherently slow. As your database grows, they will only slow down
   more.
 * Your query looks okay, so if I were you I would at minimum, cache the query results
   based on the arguments, either using Transients, or the Object Cache to prevent
   slamming your server every request.
 * [https://codex.wordpress.org/Class_Reference/WP_Object_Cache](https://codex.wordpress.org/Class_Reference/WP_Object_Cache)
 *  [Oleksandr Strikha](https://wordpress.org/support/users/shtrih/)
 * (@shtrih)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/multiple-filter-too-slow/#post-7382339)
 * The simplest solution is cache.
    But if it’s not possible to use cache in your
   case, you can try to add custom index for wp_postmeta table. `CREATE INDEX meta_value_idx
   ON wp_postmeta (`meta_value`(20));` The number “20” should be increased in case
   you have long team names.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Multiple Filter Too Slow’ is closed to new replies.

## Tags

 * [custom field](https://wordpress.org/support/topic-tag/custom-field/)
 * [custom post type](https://wordpress.org/support/topic-tag/custom-post-type/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 3 replies
 * 4 participants
 * Last reply from: [Oleksandr Strikha](https://wordpress.org/support/users/shtrih/)
 * Last activity: [9 years, 11 months ago](https://wordpress.org/support/topic/multiple-filter-too-slow/#post-7382339)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
