i Put search widget in my website (default Wordpress 3.0.4). The default output will be
<form action="http://alessandro.host/" id="searchform" method="get" role="search">
<div><label for="s" class="screen-reader-text">Search for:</label>
<input type="text" id="s" name="s" value="">
<input type="submit" value="Search" id="searchsubmit">
</div>
</form>
now i want to override that to make the output will be like this
<form action="http://alessandro.host/" id="searchform" method="get" role="search">
<div>
<input type="text" id="s" name="s" value="Search">
</div>
</form>
Notice there is no label and send button
how i can make it?
You will need to rename your search.php to searchform.php and place it in your theme folder. Wordpress first checks the file in current theme folder and if not found then it displays the default template.
I think you need this and this.
It describes both ways, adding your template or override the basic search form/criteria.
Happy Coding
Related
In my WordPress v5.5.1, I have custom post 'song'.
I have the below search form in my header for all pages:
<form>
<input type="hidden" value="song" name="post_type" id="post_type" />
<input type="text" name="s" id="search" value="<?php the_search_query(); ?>">
</form>
And the search results are shown in search.php.
The search form works in all pages except the custom post_type page www.example.com/song/song-1, search query goes to 404 page not found.
Found that upon adding get and action to the form tag as below, it solves the issue:
<form class="search-form" method="get" action="<?php echo bloginfo('url') ?>">
<input type="hidden" value="song" name="post_type" id="post_type" />
<input type="text" name="s" id="search" value="<?php the_search_query(); ?>">
</form>
I'm using custom WordPress template and I don't know how to add search box in a specific place. Of course my template contains search box, but it is in a weird place, so I would like to add custom one. I cannot do that by adding widget. I have to edit index.php to add search box.
When I add this:
<form method="get" id="searchform" action="<?php bloginfo('home'); ?>/">
<div><input type="text" size="18" value="<?php echo wp_specialchars($s, 1); ?>" name="s" id="s" />
<input type="submit" id="searchsubmit" value="Search" class="btn" />
</div>
</form>
Basically, it is working. It is searching properly, but the search box is bad looking.
That one works as well:
<form method="get" id="search_form" action="<?php bloginfo('home'); ?>"/>
<input type="text" class="text" name="s" value="SEARCH" >
<input type="submit" class="submit" value="" />
</form>
But again, it looks awfull. I have to have custom css too.
And another one:
<?php get_search_form(); ?>
Works good, but the same problem. It is just like in 2000.
I tried adding custom css, but the problem is that id does not not searching anything on my website. Instead going to http://example.com/?s=WHAT-I-TYPED it goes to http://example.com/
What can I do with that?
To solve the UGLYNESS problem: Just add the plugin 'simple custom css': https://nl.wordpress.org/plugins/simple-custom-css/. Then write some CSS to make it pretty.
To solve the SEARCH problem replace name="search" with name="s" on your input field (source: https://developer.wordpress.org/reference/functions/get_search_form/).
I have a problem.
My website is running an SSL on the checkout page. This is the current message I get.
The page at 'https://jonathanmichael.co.uk/checkout/' was loaded over
HTTPS, but is submitting data to an insecure location at
'http://jonathanmichael.co.uk/': this content should also be submitted
over HTTPS.
<form action="http://jonathanmichael.co.uk/" method="get" id="adminbarsearch"><input class="adminbar-input" name="s" id="adminbar-search" type="text" value="" maxlength="150"><input type="submit" class="adminbar-button" value="Search"></form>
My question is how do I fix this? I'm using Wordpress, I have found this code which I think links to it.
searchform.php
<!-- Start SearchForm -->
<form method="get" class="searchform" role="search" action="<?php echo home_url(); ?>/">
<fieldset>
<input name="s" type="text" id="s" placeholder="<?php _e( 'Search', THB_THEME_NAME ); ?>" class="small-12">
</fieldset>
</form>
<!-- End SearchForm -->
I have zero knowledge of PHP for help would be appreciated.
Thanks!
Easy. Just explicitly change the form action to:
<form action="https://jonathanmichael.co.uk/checkout/"
Also, please use $_POST for your form.
$_GET should not be used for anything that is supposed to be secure.
<form action="https://jonathanmichael.co.uk/checkout/" method="POST" id="adminbarsearch">
You need to pass the $scheme parameter to the call to home_url()
This will let you generate the link with the https:\\ prefix.
See the documentation: http://codex.wordpress.org/Function_Reference/home_url
<!-- Start SearchForm -->
<form method="get" class="searchform" role="search" action="<?php echo home_url($scheme = https); ?>/">
<fieldset>
<input name="s" type="text" id="s" placeholder="<?php _e( 'Search', THB_THEME_NAME ); ?>" class="small-12">
</fieldset>
</form>
<!-- End SearchForm -->
Currently I have 1 custom post type called 'guides' and a couple of custom fields. Now I want to display a search form on archive-guides.php where you people can search on the custom field champion.
This is my code in archive-guides:
<form id="searchform" action="<?php bloginfo('home'); ?>/" method="get">
<input id="s" maxlength="150" name="s" size="20" type="text" value="" class="txt" />
<input name="post_type" type="hidden" value="guides" />
<input id="searchsubmit" class="btn" type="submit" value="Search" />
</form>
This is my code in search.php:
<?php
$search_refer = $_GET["post_type"];
if ($search_refer == 'guides') {
if ('meta_key=champion&meta_value=$search_query') { load_template(TEMPLATEPATH . '/search-guides.php'); } };
?>
But It still wouldnt redirect to search-guides.php, if I search with the form the url will become /?s=query&post_type=guides (query = search term).
Any help appreciated!
I think https://wordpress.stackexchange.com/questions/89886/how-to-create-a-custom-search-for-custom-post-type post will help you to create custom search for custom post type.
Also helpful: http://www.wpbeginner.com/wp-tutorials/how-to-create-advanced-search-form-in-wordpress-for-custom-post-types/
Please update with your code for load_template.
How do I make this code (custom):
<div id="sb-search" class="sb-search">
<form>
<input class="sb-search-input" placeholder="Search.." type="text" value="" name="search" id="search">
<input class="sb-search-submit" type="submit" value="">
<span class="sb-icon-search"></span>
</form>
</div>
retrieve search results like this one ( wordpress ) does:
<form method="get" class="searchform" action="<?php echo home_url('/'); ?>">
<div>
<input type="text" class="search" name="s" onblur="if(this.value=='')this.value='<?php _e('To search type and hit enter','typegrid'); ?>';" onfocus="if(this.value=='<?php _e('To search type and hit enter','typegrid'); ?>')this.value='';" value="<?php _e('To search type and hit enter','typegrid'); ?>" />
</div>
Basically I got this custom code for an awesome search box with on-click slide etc. It has a field where people can type, but it gets no results as used on my wordpress site. I wanna make it able to get results from wordpress content w/o changing divs thus not altering its design. Please help, I'm stuck!!
This would do it:
<div id="sb-search" class="sb-search">
<form action="<?php echo home_url('/'); ?>">
<input class="sb-search-input" placeholder="Search.." type="text" value="" name="s" id="search">
<input class="sb-search-submit" type="submit" value="">
<span class="sb-icon-search"></span>
</form>
</div>
All you have to do is add the form action, and make the name of the search input to be "s".
<form method="get" class="searchform" action="<?php echo home_url('/'); ?>" >
<input class="sb-search-input" placeholder="Search.." type="text" value="" name="s" id="search">
<input class="sb-search-submit" type="submit" value="">
<span class="sb-icon-search"></span>
</form>
homeurl ?s=anything will call wordpress search function, so just make form's action GET and ACTION = your home url