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.

this is my code. It gets the variables from the url. It is very slow and sometimes don't even complete. How can I improve it?

Note: Most of the times some of the variables will not have any value. I thought that if I check this and remove it's array from the query it will improve it somehow.

$value1 = $_GET['extra1'];
$value2 = $_GET['extra2'];
$value3 = $_GET['extra3'];
$value4 = $_GET['extra4'];
$value5 = $_GET['extra5'];
$value6 = $_GET['extra6'];
$value7 = $_GET['extra7'];
$value8 = $_GET['extra8'];
$value9 = $_GET['extra9'];
$value10 = $_GET['extra10'];

$args = array(
    'meta_query' => array(
        array(
            'key' => extra1,
            'value' => $value1,
            'compare' => '='
        ),
        array(
            'key' => extra2,
            'value' => $value2,
            'compare' => '='
        ),
        array(
            'key' => extra3,
            'value' => $value3,
            'compare' => '='
        ),
        array(
            'key' => extra4,
            'value' => $value4,
            'compare' => '='
        ),
        array(
            'key' => extra5,
            'value' => $value5,
            'compare' => '='
        ),
        array(
            'key' => extra6,
            'value' => $value6,
            'compare' => '='
        ),
        array(
            'key' => extra7,
            'value' => $value7,
            'compare' => '='
        ),
        array(
            'key' => extra8,
            'value' => $value8,
            'compare' => '='
        ),
        array(
            'key' => extra9,
            'value' => $value9,
            'compare' => '='
        ),
        array(
            'key' => extra10,
            'value' => $value10,
            'compare' => '='
        )
    )
 );
$query = new WP_Query( $args );

if ( $query->have_posts() ) : 
    while ( $query->have_posts() ) : $query->the_post();
        the_title();
    endwhile;
endif;
share|improve this question

2 Answers 2

I have a hunch that meta query of this complexity is going to be crazy. I am not sure what you are trying to do without context described, but most likely there are easier way to organize that.

share|improve this answer

Not sure if this is just a typo, but your key variables are missing the $. This should trigger a fatal error. Try doing a find and replace to replace extra with $extra and see if that does the trick.

share|improve this answer
2  
Nah, unquoted stuff is treated as unknown constant and cast to string with warning. Won't trigger fatal error. –  Rarst May 31 '11 at 21:38
    
@Rarst - +1 thanks for the info...I did not know that. –  tollmanz May 31 '11 at 21:53

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.