• I want to make the search results within my WordPress site show a tag only and when I click on the tag it shows the articles related to the tag and doesn’t show the article directly when searching

    • This topic was modified 2 years, 3 months ago by Jan Dembowski. Reason: Moved to Fixing WordPress, this is not an Developing with WordPress topic

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • 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.

Viewing 1 replies (of 1 total)
  • The topic ‘Make search results within WordPress only as a tag’ is closed to new replies.