1

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'
                            ) );
2

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.

  • Awesome! Thank you, I figured it was something stupid like that :) – Stephen Feb 7 '13 at 21:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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