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.

My wordpress search form (code below) appends the query string to current page only. For example if I go to http://Website/unknown-page and then use the form to search for some content the query string looks like this http://Website/unknown-page?s=Search and only searches within the current page. It should be searching from the root like this: http://Website/?s=Search

How do I fix this?

                     <form class="form-inline" role="search">
                                  <div class="form-group">
                                    <label class="sr-only" for="search">Search:</label>
                                    <input type="text" name="s" class="form-control" placeholder="Search">
                                  </div>
                                  <button type="submit" class="btn btn-default">Submit</button>
                            </form>
share|improve this question

1 Answer 1

up vote 1 down vote accepted

When you omit the action attribute from the form tag, it defaults to the current URL. Give an explicit URL for the form's action to direct it to a specific URL-

<form class="form-inline" role="search" action="<?php echo home_url( '/' ); ?>">
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.