WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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??


share|improve this question

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


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.