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 am displaying search results in order of number of views or recency. To set the initial search results view to "views" I have this in my code:

if( !isset($_REQUEST['sorting'])) {
    $_REQUEST['sorting'] = "views";
}

However, if I include this code, then if there are no matches, it still displays all of the results for that category. If I remove this code, the search results display correctly. How can I set the default view without destroying the search results? And why does this code affect it??

Thanks!

share|improve this question
    
Might wanna consider accepting some answers to your previous questions - 0% accept rate tends to give out a bad vibe, and we're all about community here! –  TheDeadMedic Aug 5 '12 at 20:31

1 Answer 1

A colleague of mine gave me this helpful answer, I hope it helps others:

"To answer definitively, I would need to see a bit more code. Nonetheless, WordPress does override $_REQUEST, so depending on where this code is placed, it may be overwritten. So assuming that the parameter is being passed in the URL, I would try:

if( !isset($_GET['sorting'])) { $_GET['sorting'] = "views"; } 
share|improve this answer

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.