Hi @iqbrb, if I’m understanding correctly, you’re trying to implement a search field on your WordPress site to search for tags and then link off to the tag archive page, correct?
If you are intending on hooking into existing search templates so you can take advantage of pagination and existing search functionality, it would be tricky (though not impossible), as the WordPress search is build to search for posts (or other post types), not terms.
I’d actually recommend creating a custom search form on a template or block that you’d implement. You’ll want to make sure you’re implementing a nonceonto the form to ensure your form is implemented securely and that you’re sanitizing any input before using.
A general outline of how I’d recommend approaching this:
1) Create form with search field and custom input names that you’ll be able to determine if the tag search was performed.
2) If the search was performed, call get_terms() and pass something like [ 'search' => $search_term, 'taxonomy' => 'post_tag' ]
to the $args
parameter.
3) Output the results from that function which will be all the tags that match the query
4) If you want to implement pagination, you could pass number
and offset
arguments to the $args parameter and implement a custom pagination.
Hope that helps put you on the right path.