I have a custom post type 'Artist'. I also have individual artist pages for each of my 3 artists. I limited my default wordpress search to search only for 'Artist' post type using this in the functions.php file.
function searchfilter($query) {
if ($query->is_search && !is_admin() ) {
$query->set('post_type',array('Artist'));
}
return $query;
}
add_filter('pre_get_posts','searchfilter');
Now, How can I make sure, that if I type the artist name, it shows the search results on the artist page and not on the default search page.
Example, if I type John in the search box, the search results should show the all the content of the Artist page which contains the word John.
Here is the search.php code
<?php
if ( have_posts() ) : ?>
<?php
/* Start the Loop */
while ( have_posts() ) : the_post();
/**
* Run the loop for the search to output the results.
* If you want to overload this in a child theme then include a file
* called content-search.php and that will be used instead.
*/
<?php the_title(); ?>
<?php the_content(); ?>
endwhile;
the_posts_navigation();
else :
get_template_part( 'template-parts/content', 'none' );
endif; ?>