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.

The array below with "'taxonomy' => 'age'" isn't working, if I copy and paste the array "array( '19', '20' )" in place of the variable it works fine. I just started picking up PHP so go easy on me :)

                if($_REQUEST["price"] == 19){$price = "'19'";}
                elseif($_REQUEST["price"] == 20){$price = "array( '19', '20' )";}
                elseif($_REQUEST["price"] == 21){$price = "array( '19', '20', '21' )";}
                elseif($_REQUEST["price"] == 22){$price = "array( '19', '20', '21', '22' )";}
                elseif($_REQUEST["price"] == 23){$price = "array( '19', '20', '21', '22', '23' )";}
                echo $price;
                $my_query = new WP_Query( array(
                            'post_status' => 'publish',
                            'post_type' => 'post', 
                            'cat' => '' . $_REQUEST["category"] . '',
                            'tax_query' => array(
                                    'relation' => 'OR',
                                    array(
                                        'taxonomy' => 'age',
                                        'field' => 'id',
                                        'terms' => '' . $_REQUEST["age"] . ''
                                    ),
                                    array(
                                        'taxonomy' => 'price',
                                        'field' => 'id',
                                        'terms' => $price,
                                        'operator' => 'IN'
                                    ),
                                    array(
                                        'taxonomy' => 'group',
                                        'field' => 'id',
                                        'terms' => '' . $_REQUEST["group"] . ''
                                    )
                                ),
                            'posts_per_page' => '-1'
                            ) );
share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

Your array definitions aren't correct. This...

elseif($_REQUEST["price"] == 20){$price = "array( '19', '20' )";}

... creates a literal string that reads "array( '19', '20' )". Remove the quotes.

elseif($_REQUEST["price"] == 20){$price = array( '19', '20' );}

That should give you PHP arrays.

share|improve this answer
    
Awesome! Thank you, I figured it was something stupid like that :) –  Stephen Feb 7 '13 at 21:12
add comment

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.