Support » Fixing WordPress » How to direct user to specific search term result?

  • Hello, I want the user to redirect to a specific search term
    I am using the wordpress default search bar okay so when the user searches for ford it will show all the blog posts and available listings for ford on the index.php page
    now if the user searches for the “careers” term they will see results related to the career search term.

    What I want is when they search for ‘careers’ they should automatically direct to the careers page, when they search for ford 150 they should direct to the inventory page with a search filter applied which will show ford listings. when they search for something else it should show blog posts or related stuff.

    How to make a search like this?
    can someone help?
    Thanks

    • This topic was modified 3 days, 10 hours ago by Steven Stern (sterndata).
    • This topic was modified 2 days, 11 hours ago by Jan Dembowski. Reason: Moved to Fixing WordPress, this is not an Developing with WordPress topic
Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    Those sound like two entirely different object types, such as categories and products. A single search field cannot immediately discern one type the another. If you want to stay with one search field, you’d need to pre-query categories with the provided search term to see if such a category actually exists. If there are other possible object types, you’d pre-query for those as well. When there are no matches in any pre-query, you can continue with the default search.

    This logic could be implemented through the “template_redirect” action. From there you can redirect where appropriate, or simply return to continue with the default search process.

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.