0

So I have a .html page under my Wordpress website and I want to be able to use the search button on the static html page to search the search.php page, is that possible?

Is this correct? This is located inside my test.html:

<div class="search_bar-wrapper">
    <input type="text" class="search_bar search-input evt-search-input-wp" placeholder="Search"
    value="<?php echo get_search_query(true); ?>"/>
    <button class="btn-fh btn-secondary search-btn search-btn-overlay">
        <i class="custom-icon icon-icon_small_arrow_right"></i>
    </button>
    <div class="clearInput"><img src="/images/icon_close.svg" alt="" /></div>
</div>

Would I need to point a form="submit" and action=".." on the input instead? If so, what would the action need to point too?

1
  • 1
    search.php doesn't actually perform a search, all the searching is done and finished long before search.php is loaded, it just displays the results afterwards. Infact you can have a theme with only an index.php template and search will still function
    – Tom J Nowell
    Commented Apr 6, 2021 at 16:39

1 Answer 1

2

If you want to submit a form you need a <form> element to contain the input. (You can get away without one but you'd need script to fake the submit.) The action is the homepage with the search text in an input named 's', e.g.

<form method="get" action="https://example.com/">
    <input type="search" name="s" />
    <input type="submit" value="Search" />
</form>

for a bare-bones form. Or you can use get_search_form() to get a version with all of the ARIA attributes set up too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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