search – Need help to be able to searching by tag and title

Question

Hello I am trying to get my search bar to search by titles and tags. I have a function working to search by titles but I cant seem to figure out how to search by tags. I have added the code below to my function.php I got this from https://wordpress.org/support/topic/search-within-results-tags-date-archive/

function search_archive_title() {
$type="";
$var="";

if (is_tag()){
   $var = single_tag_title( '', false );
   $action = 'tag/'.$var."https://wordpress.stackexchange.com/";
}
}
echo '<form role="search" method="get" class="search-form" action="/'.$action.'">';
echo '<input type="text" name="s" value="" />';
echo '<button>Search</button>';
echo '</form>';


add_filter( 'posts_search', 'search_archive_title', 11, 2 ); 

I would very much appreciate some help Ive been trying a lot of things. I was trying with wp-query before but that wasn’t working so I figured I would try this but if you have a better idea please let me know.

0
catsanddogs90 1 month 2023-02-08T18:38:26-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse