Modifying searchform.php and search.php to have two kinds of searches

For anyone trying to achieve something similar, here’s how I solved it: In searchform.php, duplicate the form, as such: <form method=”get” id=”searchform” action=”<?php echo esc_url( home_url( “https://wordpress.stackexchange.com/” ) ); ?>”> <input type=”text” name=”s” id=”s” placeholder=”<?php esc_attr_e( ‘Search by Post’ ); ?>” /> <input type=”hidden” name=”search-type” value=”posts” /> <button type=”submit” name=”submit” id=”searchsubmit” value=”<?php esc_attr_e( ‘Search’ ); … Read more

Adding arg to search results page

That site you linked to is completely wrong. You should never ever use query_posts to run any type of query. Take your time and read the following post on this matter: When should you use WP_Query vs query_posts() vs get_posts()? You also would not want to run any type of custom query in place of … Read more

Rewriting search permalink

WordPress doesn’t know that you want the path /searchmyblog/ as search result base. So when it sees the a it tries to find the best match – in your case a post starting with this letter. To fix that you could modify my code for the pagination base to change the search base: if ( … Read more

Customise search form in the Widget

if your theme have not search-form.php file then you will create the file and add the custom css there. Because search widget is calling the get_search_form() function. First it will search the search-from.php file from activated theme folder. If there have no file then it will call wp’s default search form. See the Codex

Exclude custom post type from search by custom field value?

You need to implement a hook for pre_get_posts filter, in which you can set what you need. Pay attention that you should change only search query, so you have to check if is_search() method returns true. The hook should look like this: add_filter( ‘pre_get_posts’, ‘wpse8170_pre_get_posts’ ); function wpse8170_pre_get_posts( WP_Query $query ) { if ( $query->is_search() … Read more

search.php template not loading results

Change the form to: <input class=”searchform-mid clearit” type=”text” name=”s” id=”search-header” value=”Search” /> Check that name should be “s” as that the get attribute wordpress use for search keyword

Using next/previous_posts_link with customised search

You don’t need the type variable and other bits of custom search query code, or custom functions like the other answers. In your searchbox, instead of submitting the form to / submit it to /my_post_type/ instead! WordPress will handle all the rest for you automagically, with no effort involved. What’s more this means all the … Read more

Set minimum number of characters in the search

Quick and dirty, put this before your get_header() in your search.php <?php // Get the query string $query = get_search_query(); // if the first & last char is space, rip them $query = trim($query); // if there are more than one space, rip to one space $query = preg_replace(‘/\s\s+/’, ‘ ‘,$query); // if chars count … Read more

Search Post Title Only [duplicate]

I didn’t test the code below, but I guess it works. /** * Search SQL filter for matching against post title only. */ function __search_by_title_only( $search, &$wp_query ) { /*my solution */ if($_GET[‘post_type’] != ‘attorney’ ) return $search; /*my solution*/ //please copy the rest of the code from the link below } add_filter( ‘posts_search’, ‘__search_by_title_only’, … Read more