database query with more than a couple meta hangs and doesn’t complete

I have a development website with about 70 checkboxes for custom fields. The idea is the user selects one or more checkboxes, it queries the database for all posts that have a meta_key for the checkbox, and returns the results.

My code below works great for 1-3 checkboxes at a time. 4 checkboxes or more results in a hosting error “Unable to Serve This Request”, connection timed out message.

Read More

The error is not dependent on the # of results returned. 4 checkboxes which should return around 20 results fails, while 2 checkboxes for 170 results is no problem.

Here’s how I have built my query – is there anything inheritly wrong with my logic?

$args=array(
    'post_type' => array ( 'resources'),
    'post_status' => 'publish',
    'posts_per_page' => -1,
    'orderby' => title,
    'order' => ASC,

    'meta_query' => array(
            'relation' => 'OR')
            );      

   // Add filters
   // I have an array above with the $name and value of the meta_key

   array_push($args['meta_query'], array('key'=>$name, 'value'=> $value)); 

    $my_query = null;
    $my_query = new WP_Query($args);

    if ( $my_query->have_posts() ) {

    while ($my_query->have_posts()): $my_query->the_post();
     // Show results
    }

Related posts