admin管理员组

文章数量:1297075

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?

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?

Share Improve this question asked Apr 6, 2021 at 16:17 DevSemDevSem 2092 silver badges10 bronze badges 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
Add a comment  | 

1 Answer 1

Reset to default 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/">
    <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.

本文标签: phpSearch WordPress using static html page