I want empty search returns to home page in my wordpress

This will do exactly what you’re asking for: add_action(‘wp’, ‘redirect_empty_search’); function redirect_empty_search() { global $wp_query; if( isset( $_REQUEST[‘s’] ) && 0 === $wp_query->post_count ) { wp_redirect( home_url() ); exit; } } You’ll want to add some kind of message on the homepage when this happens, maybe by adding a query parameter to home_url() and displaying … Read more

Search using WP_Query

Add this line – <?php $search_query[‘post_type’] = ‘products’; ?> Just before the line – <?php $search = new WP_Query($search_query); ?>

Included posts on a page searchable

The problem is that by default WordPress only looks in the title and content field. As you build your pages from multiple pieces of external post types the default query doesn’t find those parts. Before we go any further I want you to know that this is going to be quite involved as you need … Read more

Search result count not matching actual result

If you want to exclude certain posts, wouldn’t the conditional be: if ($value != ” && get_post_meta($post->ID, ‘value’, true) != ‘value_to_exclude’) Anyhow, you’re excluding AFTER you run the query. So $total_results will always be ‘wrong’. The better approach is to write sql for WP_Query that does the excluding for you. But you didn’t include the … Read more

Prevent search query from taking place when using Google CSE?

Same issue with you and just found it out on stackexchange. Put codes below in the function.php in your theme. function _cancel_query( $query ) { if ( !is_admin() && !is_feed() && is_search() ) { $query = false; } return $query; } add_action( ‘posts_request’, ‘_cancel_query’ ); Here’s the source

WP + Google analytics = /search?

Search code comes with wordpress.If you remove search box it does not mean that search page is removed. If you want that google should not crawl your search page then you can specify in your robot.txt file like below : Disallow: /search

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)