Custom Search Bar Redirection Setup for Product and Post

This topic has 4 replies, 2 voices, and was last updated 2 months, 1 weeks ago ago by Luca Rossi

  • Avatar: Drishti
    Drishti
    Participant
    October 7, 2024 at 23:19

    I’ve created a custom search page using the theme editor, and I have two search bars on my site with different purposes. I would like assistance with the following redirection setup:

    1) Post Archive Search Bar:

    When a user searches from the search bar on the post archive page, I want the search to redirect to the custom page I’ve created specifically for post searches.

    2) Header Search Bar:

    When a user searches from the header search bar, it should redirect to the shop page with the relevant search filters applied, instead of the custom post search page.

    Could you guide me on how to implement these different redirections for the two search bars?

    Thank you for your support, and let me know if you need any further information.

    Please, contact administrator
    for this information.
    Files is visible for topic creator and
    support staff only.
    3 Answers
    Avatar: Justin
    Luca Rossi
    Support staff
    October 8, 2024 at 12:29

    Hi @Drishti,

    Please try adding this custom code under functions.php file locates in your child theme:

    
    add_action('etheme_elementor_search_before_input', 'n2t_etheme_elementor_search_before_input');
    function n2t_etheme_elementor_search_before_input(){
    echo '<input type="hidden" name="post_type" value="product" />';
    }
    

    Hope it helps!

    Avatar: Drishti
    Drishti
    Participant
    October 9, 2024 at 19:17

    Hi,

    I’ve added custom code to the child theme’s functions.php file, but all search queries are currently redirecting to the shop page. Here’s what I need:

    i) If the user searches from the header, it should redirect to the shop page with the search term.
    ii) If the user searches on the blog page, it should redirect to a custom blog search results page with the searched term.

    I’ll share the relevant URLs in the private section for clarity.

    Please contact administrator
    for this information.
    Avatar: Justin
    Luca Rossi
    Support staff
    October 10, 2024 at 17:09

    Dear Drishti,

    We hope this message finds you well.

    Could you kindly remove the Ajax Search Header Element and replace it with the standard Search element? For your reference, here is a screenshot: [https://prnt.sc/BXsaZDq3FcqV](https://prnt.sc/BXsaZDq3FcqV).

    We hope this information is helpful. Please feel free to reach out if you need any further clarification.

    Best regards,
    8Theme Team

  • Viewing 4 results - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.Log in/Sign up

Helpful Topics

We're using our own and third-party cookies to improve your experience and our website. Keep on browsing to accept our cookie policy.