admin管理员组文章数量:1389807
I'm currently building a custom WordPress template and I've run into a problem with the search box.
When I use the searchbox from the homepage, it works as intended. It also works as long as Permalinks are set to default. (url/?page_id=1
)
However, when I use the searchbox from another page when using pretty permalinks, the URL looks something like this:
/?s=query
and a 404 page appears.
My search box code looks like this
<form id="search-query">
<div class="search-box">
<form role="search" method="get" id="searchform" class="searchform" action="/index.php">
<div>
<label class="screen-reader-text" for="s"><?php _x( 'Search for:', 'label' ); ?></label>
<input type="text" value="<?php echo get_search_query(); ?>" name="s" id="s" />
<input type="submit" id="searchsubmit" value="<?php echo esc_attr_x( 'Search', 'submit button' ); ?>" />
</div>
</form>
</div>
</form>
Here's the site's URL if anyone's want to take a look: /
Any help is very appreciated!
I'm currently building a custom WordPress template and I've run into a problem with the search box.
When I use the searchbox from the homepage, it works as intended. It also works as long as Permalinks are set to default. (url/?page_id=1
)
However, when I use the searchbox from another page when using pretty permalinks, the URL looks something like this:
http://url/pretty-page-title/?s=query
and a 404 page appears.
My search box code looks like this
<form id="search-query">
<div class="search-box">
<form role="search" method="get" id="searchform" class="searchform" action="/index.php">
<div>
<label class="screen-reader-text" for="s"><?php _x( 'Search for:', 'label' ); ?></label>
<input type="text" value="<?php echo get_search_query(); ?>" name="s" id="s" />
<input type="submit" id="searchsubmit" value="<?php echo esc_attr_x( 'Search', 'submit button' ); ?>" />
</div>
</form>
</div>
</form>
Here's the site's URL if anyone's want to take a look: http://hermodsgymnasiet-develop.kaigan.modxcloud/
Any help is very appreciated!
Share Improve this question asked Nov 25, 2015 at 15:36 ErikaErika 1071 silver badge6 bronze badges 1 |2 Answers
Reset to default 0Currently your form looks like:
<form id="search-query">
<p class="in-english"><a href="http://localhost/hermodswp/?page_id=76">Information in English</a></p>
<div class="search-box">
<div>
<label class="screen-reader-text" for="s"></label>
<input type="text" value="sdf" name="s" id="s" style="width: 293px;">
<input type="submit" id="searchsubmit" value="Sök">
</div>
</div>
</form>
Try adjusting your submit action to point to your home_url().
action="<?php echo home_url(); ?>"
You can edit the page in Chrome to see that this works fine.
<form role="search" id="search-query" method="get" action="http://hermodsgymnasiet-develop.kaigan.modxcloud/">
<p class="in-english"><a href="http://localhost/hermodswp/?page_id=76">Information in English</a></p>
<div class="search-box">
<div>
<label class="screen-reader-text" for="s"></label>
<input type="text" value="" name="s" id="s" style="width: 293px;">
<input type="submit" id="searchsubmit" value="Sök">
</div>
</div>
</form>
Simply add action="/"
to your form!
本文标签: phpSearch only working on front page (index)not working on other pages
版权声明:本文标题:php - Search only working on front page (index) , not working on other pages 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744601216a2615077.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
http://url/pretty-page-title/?s=query
with a bundled theme-- one of the "Twenty {Something}" ones. – s_ha_dum Commented Nov 25, 2015 at 15:55