I just did a normal form that redirects the results from index.php to search.php, where I pasted the normal loop code of my index.php that displays the latest posts, and I noticed only the posts from my search query appears. I did not put any filters with $_GET in the loop, is it possible search.php automaticly filters the loop to get results that matches my search???


The loop doesn not display the latest posts, it just shows the posts the main query has found. On your search page the main query returns search results, and you can change its order (we have plenty of examples for that on our site).

WordPress looks for the parameter s or /search/ in the request URI and decides to do a search query then. That’s what you see as results. You don’t have to do anything more, if you are happy with those results. It happens automatically.

Your Answer

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