Search Function on Wordpress site is not working - php

I am working on the website, www.carsofchange.com, and the search function is working. It returns, "Sorry, no posts matched your criteria." for all searches.
I'm using the Sleek Child Theme and the Genesis platform.
I opened the PHP file that runs the search but I am not search how to know if this is where the error is. The PHP file is below:
<div id="topnav">
<div class="wrap">
<!-- end #topnav <p>
<a class="rss-topnav" rel="nofollow" href="<?php bloginfo('rss_url'); ?>"><?php _e("Posts", 'genesis'); ?></a>
<a class="rss-topnav" rel="nofollow" href="<?php bloginfo('comments_rss2_url'); ?>"><?php _e("Comments", 'genesis'); ?></a>-->
<p>
<form method="get" id="searchform" action="<?php bloginfo('home'); ?>/">
<input type="text" size="put_a_size_here" name="s" id="s" value="Search" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;"/>
<input type="submit" id="searchsubmit" value="Search" class="btn" />
</form></p>
</div><!-- end .wrap -->
</div><!-- end #topnav -->
It doesn't seem like a CSS error and I've tried turning on and off the Search Everything plugin without any luck. Thank for you time and any help you can provide.

Try with this code:
<form method="get" id="search-form" action="<?php echo esc_url( home_url( '/' ) );?>">
<input type="text" class="field" name="s" id="input-text" placeholder="<?php esc_attr_e( 'Search', 'themename' ); ?>" />
<input type="submit" class="submit" name="submit" id="searchsubmit" value="<?php esc_attr_e( '', 'themename' ); ?>" />
</form>

Related

how can I change placeholder text depend on language

Hello I am newbie and I would like to ask how is it possible to change the placeholder depend on language?. I have a multilingual wordpress site and I wrote this code on a .php file :
<form class="search" id="searchform" action="<?php echo home_url(); ?>/" method="get">
<fieldset>
<span class="text"><input name="s" id="s" type="text" value="" placeholder="<?php echo __('Search', 'alora'); ?>" />
</span>
</fieldset>
</form> `
I also tried this:
<form class="search" id="searchform" action="<?php echo home_url(); ?>/" method="get">
<fieldset>
if (get_locale() == "en_US") {
<span class="text"><input name="s" id="s" type="text" value="" placeholder="<?php echo __('Search', 'alora'); ?>" />
</span>
}
else {
<span class="text"><input name="s" id="s" type="text" value="" placeholder="<?php echo __('Search_el', 'alora'); ?>" />
</span>
}
</fieldset>
</form>
But with no luck. Can anyone please help me?.
I also read this post Change text depending on language, but I couldn't figure it out.
<?php echo _e('Search_el', 'alora'); ?>" />
Please use this..
if above code not working than use..
printf(__('Search_el', 'alora'));

Wordpress search form with Multisite

I have created a form to search posts in my blog, but my search returns posts from other blog (domain.com/) instead of (domain.com/myblog), yes is a multisite wordpress. i tried everything, follows my code:
<form class="navbar-form navbar-right searchform" role="search" method="get" id="searchform" action="<?php echo esc_url( home_url( '/' ) ); ?>">
<div class="form-group">
<input name="s" id="s" type="text" class="form-control" placeholder="Search Programs" value="<?php echo get_search_query(); ?>">
</div>
<a id="searchsubmit" type="submit" class="btn"><span class="glyphicon glyphicon-search" aria-hidden="true"></span></a>
</form>
you can resolve this problem by adding the following code in functions.php
function custom_pre_get_posts($query)
{
$parent_categories = ('myblog');
// you can search by slug or insert the category id directly. your choice
$cat_term_id = get_category_by_slug($parent_categories)->term_id;
if ($query->is_main_query() && !is_admin() && is_search())
$query->set('cat', $cat_term_id);
}
}
add_action('pre_get_posts', 'custom_pre_get_posts');
<form class="ms-global-search_form" method="get" action="<?php echo get_bloginfo('url').'/myblog/'; ?>">
<input id="s" class="field" name="mssearch" type="text" placeholder="Search across network sites:" size="16" tabindex="1" />
<input type="submit" id="searchsubmit" class="button submit" value="<?php _e( 'Search', 'ms-global-search' )?>" tabindex="2" />
</form>

Wordpress search function not working

I am fleshing out my first custom Wordpress theme and trying to hook up the search. Now I am following the codex but does not appear to be working correctly. Perhaps I am doing something wrong?
I have added the theme support as this is using the HTML field method.
so here is my search field:
<form role="search" method="get" class="search-form" action="<?php echo home_url( '/' ); ?>">
<label>
<input type="search" class="search-field" placeholder="What are you looking for?" value="<?php echo get_search_query() ?>" name="s" title="<?php echo esc_attr_x( 'Search for:', 'label' ) ?>" />
</label>
<br />
<button class="button-search">Find items</button>
</form>
And I have created a search.php with the usual template page bits along the top, created the search page as a page in wordpress, yet when I search I can see the post request in the URL but the page is blank. I am cleary doing something wrong here?
This should work for you
<form role="search" method="get" class="search-form" action="<?php echo esc_url( home_url( '/' ) ); ?>">
<label>
<input type="text" class="search-field" placeholder="What are you looking for?" value="<?php echo get_search_query() ?>" name="s" id="s" title="<?php echo esc_attr_x( 'Search for:', 'label' ) ?>" />
</label>
<br />
<input type="submit" class="button-search" id="searchsubmit" value="Find items" />
</form>

wordpress search for only single category

I am creating a news website at index page i listed all news by categories i created 1 more category for one of my news section that is recipes now what i want is i am creating a search
form for that section only that filter the search for only recipe category,how can i do that i wanted to know basically i created a normal search.php page as per wordpress standard code
that filter news from through out the theme.
please help me out.
here is a code in form page:
<div class="search_box">
<form method="get" id="searchform" action="<?php echo esc_url( home_url( '/' ) ); ?>">
<div class="input-group">
<input type="text" class="form-control search-bar eng my_control" name="s" id="search" placeholder="<?php echo esc_attr_x( 'Search …', 'placeholder', 'dastak' ); ?>" value="<?php echo esc_attr( get_search_query() ); ?>" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;"/>
<span class="input-group-btn">
<input type="submit" class="search-submit btn my-btn" value="<?php echo esc_attr_x( 'Search', 'submit button', 'dastak' ); ?>">
<!-- <button class="btn my-btn" id="searchsubmit" type="button"><span class="glyphicon glyphicon-search"></span></button> -->
</span>
</div><!--input group-->
</form>
</div><!--search box-->
<div class="clearfix"></div>
You could implement a function to catch the search but defining the category in the category__in array.
global $wp_query;
if(is_search()) :
$cat = array(
'category__in' => array(5) // Where 5 is the ID of your Music category
);
$args = array_merge( $wp_query->query, $cat );
endif;
query_post($args);
OR
You could do it this way through the hidden field - value 22 is the category
<form method="get" id="search form" action="/">
<div>
<input type="text" value="" name="s" id="s" />
<input type="hidden" value="22" name="cat" id="scat" />
<input type="submit" id="search_submit" name="Search" value="Search"/>
</div>
</form>
You have to hook the WordPress WP_Query global instance and add whatever conditions you want.
Start reading about preg_get_posts WordPress hook. You'll find two examples about categories.

searchform not working in header.php

ok i have a problem with the search i'm creating a new blog in wordpress and it's not working at all i tried a lot and nothing change
this is the header.php code
<div class="navbar-r">
<form method="get" id="searchform" action="<?php bloginfo('url'); ?>">
<input class="in-s-n" type="text" name="s" <?php the_search_query();?> />
<input class="su-s-n" type="submit" value="Find" />
</form>
</div>
<!--End navbar-r-->
and when i search the page get blank
what do i have to do? any help
Try using something like:
<form role="search" method="get" id="searchform" class="searchform" action="<?php esc_url( home_url( '/' )); ?>">
<div>
<label class="screen-reader-text" for="s"><?php _x( 'Search for:', 'label' ); ?></label>
<input type="text" value="<?php get_search_query(); ?>" name="s" id="s" />
<input type="submit" id="searchsubmit" value="<?php esc_attr_x( 'Search', 'submit button' ); ?>" />
</div>
For more details, check out this link: http://codex.wordpress.org/Function_Reference/get_search_form

Categories