Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

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
    }
share|improve this question
    
Must be a tough question to answer. For now I'm just going to make JQUERY limit the checkboxes to three choices. Bummer I couldn't figure it out. –  916 Networks May 28 '13 at 16:57
    
Problem is that each additional meta_query is an INNER JOIN. It is a known issue, and not sure there is a great work-around except to write the SQL onself... Here is some documentation on the issues: core.trac.wordpress.org/ticket/19729 –  GhostToast May 31 '13 at 19:40
    
GhostToast, thanks for the clarification on this! –  916 Networks Jun 10 '13 at 17:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.