Set default text for the_search_query();

Do not hard code a value in the search field. You will get a lot of nonsense searches because people do not expect that they have to clean up the field before they can actually type something into it. They will just type and hit enter. Alternatives: Use the placeholder attribute. You can style it … Read more

How to search only by post title and category?

You’ll have to write a custom WP_Query in search.php. Also since you want to search in post_title + categories, you might have to run 2 separate queries and merge results of them into 1. Something like: $q1 = get_posts(array( ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘posts_per_page’ => ‘-1’, ‘s’ => get_search_query() )); $q2 = get_posts(array( … Read more

How to block specific keywords from searching on WordPress?

You are looking for pre_get_posts. This action is run between the composition of a (search) query and the actual query, to allow you to change the query. So, it would allow you to intercept banned keywords like this: add_action( ‘pre_get_posts’, ‘wpse338558_intercept_banned_keywords’ ); function wpse338558_intercept_banned_keywords ($query) { $banned = array (‘word1′,’word2′,’word3’); if (in_array ($query->query_vars[‘s’], $banned)) $query->s=””; … Read more

Include different loop templates in search query

I would recommend using content-{posttype}.php method, where you only have HTML markup, template tags for posts or custom post types and leave loops outside of those files. See Twenty Eleven for more detailed example. After this change you can easily modify search.php and include specific content markup based on post type. if ( have_posts() ) … Read more