How to improve WordPress search

WordPress › Relevanssi – A Better Search « WordPress Plugins Key features: Search results sorted in the order of relevance, not by date. Fuzzy matching: match partial words, if complete words don’t match. Find documents matching either just one search term (OR query) or require all words to appear (AND query). Search for phrases with … Read more

Search by word, category, tag, author

You’ll want to add some radio buttons inside your search form. Then add a filter to your search: function filter_search( $query ) { if( $query->is_search ) { if ( isset($_GET[‘tag’]) ) // alter your search query here. } return $query; } add_filter( ‘pre_get_posts’ , ‘filter_search’ ); Influenced by http://wordpress.org/support/topic/how-to-add-search-filter-by-custom-values#post-1463329

search through post-type attachments titles

You should try applying the s(search) as parameter for your custom query. See this example here: $query = new WP_Query( ‘s=keyword’ ); and you can then apply normal loop to iterate through your results. This also performs string match same as like operator %keyword% you mentioned in comment for @Ravs’ answer. Refer documentation here.

If No Search Results, Show Posts from Alternate Search Query

I’ve never seen it done before but the logic of the PHP IF/ELSE should mean you could simply plug a new query in after the ELSE: if ( have_posts() ) : while ( have_posts() ) : the_post(); get_template_part ( ‘templates/post’, ‘main’ ); endwhile; else: $the_query = new WP_Query( $args ); if ( $the_query->have_posts() ) : … Read more

Changing the search results destination URL

You can create a new page. Let’s say you want to have: http://example.com/mysearch/ Create a page that will have that URL structure. Next, Search form -> Go to and on you search form action do: <form role=”filter-search” method=”get” id=”sd_searchform_filter” action=”<?php echo home_url( ‘/mysearch/’ ); ?>”>… Now go to functions.php (or where you want this function) … Read more

Conditional tag search-no-results

There is no conditional tag for no results on a search page, but you can create yourself one. You basically just have to check the value of $wp_query->found_posts, if it is 0, returns false, any other value, returns true function is_search_has_results() { return 0 != $GLOBALS[‘wp_query’]->found_posts; }

custom search result page

I have some recommendations for your question: First: stop using query_posts(). See the codex about this function to see why you shouldn’t use it in themes or plugins. Anyway, if you are in a some weird situation where you have not option and you need to use query_posts(), you should run wp_reset_query() after the loop. … Read more