Make archive page show up in search results?

The issue is that an archive isn’t a post, it’s not something that can be shown in the loop. On your search results page, you’ll have to add some code to search categories for a similar name. You can accomplish this with the generic get_terms. Pass the searched term as the name__like argument (or maybe … Read more

Display Search Results after search 1st link

Redirecting to the first result of a search is a very unfriendly thing to do to your visitors and can quite possibly prevent them from ever finding the content they need, but it is very easy to do: function redir_first_wpse_49208() { if (is_search()) { global $wp_query; if (!empty($wp_query->posts)) { wp_redirect( get_permalink( $wp_query->posts[‘0’]->ID ) ); exit; … Read more

Show search count by post type

You’re essentially running the same query twice, instead of looping over a second query, why don’t you loop over $wp_query? $types = array(); if( have_posts() ) { while (have_posts()) { the_post(); if ( empty( $types[$post->post_type] ) { $types[$post->post_type] = 0; } $types[$post->post_type]++; } wp_reset_postdata(); rewind_posts(); } You’ll notice I added 3 things: The code in … Read more

Localization of WP theme

Wrap the elements of $search and $replace arrays into __() function to get the translated strings: function search_replace_search() { $search_term = esc_attr( apply_filters( ‘the_search_query’, get_search_query( false ) ) ); // Get search term $search = array( __(‘word1’), __(‘word2’) ); $replace = array( __(‘something 1’), __(‘something 2’) ); $replacePairs = array_combine($search, $replace); echo strtr($search_term, $replacePairs); } … Read more

Search for anything in site

Use mark.js, a jQuery plugin mark.js is such a plugin that is written in pure JavaScript, but is also available as jQuery plugin. It was developed to offer more opportunities than the other plugins with options to: search for keywords separately instead of the complete term map diacritics (For example if “justo” should also match … Read more

Check If search query contains something?

After the question’s update, I think that you need to set the canonical URL: add_action( ‘wp_head’, ‘cyb_search_results_canonical_URL’ ); function cyb_search_results_canonical_URL() { if( is_search() ) { $link = get_search_link(); echo ‘<link rel=”canonical” href=”‘ . esc_url( $link ) . ‘”>’; } } And your problem with duplicated content is fixed.