[wp-hackers] Expensive meta query - Is there a better way?

Robert Lusby nanogwp at gmail.com
Thu Feb 9 11:57:33 UTC 2012


Hello,

We're running a multiple meta query lookup in WordPress - however the DB 
query most be expensive as it's result in very slow (20/30 second) 
response times in PHP with only 300 posts (total) in the DB. Query below.

Is there a better way of doing the below? Essentially if $value is equal 
to key1 or key2 or key3 or key4 or key5 (the keys are numbered 
consecutively).


'post_type' => 'custom_post_type',
'meta_query' => array(
         'relation' => 'OR',
         array(
             'key' => 'key1',
             'value' => $value,
             'compare' => '=',
         ),
         array(
             'key' => 'key2',
             'value' => $value,
             'compare' => '=',
         ),
         array(
             'key' => 'key3',
             'value' => $value,
             'compare' => '=',
         ),
         array(
             'key' => 'key4',
             'value' => $value,
             'compare' => '=',
         ),
         array(
             'key' => 'key5',
             'value' => $value,
             'compare' => '=',
         ),
     )
);

Thanks,
Rob



More information about the wp-hackers mailing list