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/).
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>
My goal is to populate a hidden form field with the utm_source from url.
Basically this:
<input id="fieldihhdji" name="cm-f-ihhdji" type="hidden" value="<?php echo $_GET["utm_source"] ?>" />
The problem is this form works perfectly on one page, but not on another.
Working: museumhack.com/test-a/?utm_source=hello (form field is hidden, but populates value)
Not working: museumhack.com/test-b/?utm_source=hello (at the bottom)
It seems like the pages may be processing the double quotes differently, but not clear how to fix. Wordpress required a plugin to process on page PHP -- I installed that and don't think it's the problem.
Here is the entire form that I copy/pasted between pages:
<form action="http://museumhack.createsend.com/t/d/s/ihhykl/" method="post" id="lead-capture">
<p>
<input id="fieldName" name="cm-name" type="text" placeholder="Your Name"/>
</p>
<p>
<input id="fieldEmail" name="cm-ihhykl-ihhykl" type="email" placeholder="you#email.com" required />
</p>
<p>
<input id="fieldjuuilj" name="cm-f-juuilj" type="text" placeholder="(212)555-5555" />
</p>
<p>
<input id="fieldihhdji" name="cm-f-ihhdji" type="hidden" value="<?php echo $_GET["utm_source"] ?>" />
</p>
<p>
<button type="submit">Request Quick Quote</button>
</p>
Thanks,
Try this code , this might help you
<input id="fieldihhdji" name="cm-f-ihhdji" type="hidden" value="<?php echo $_GET['utm_source']='';?>">
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
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