• I am looking at how to search multiple exterior sites from within WordPress. I essentially want to redirect the search to different locations, based on the selection made in a drop down menu. If the user selects “website” it would search the WordPress blog. If the user selects “site1”, it would take the input and pass the user along to https://www.site1.com.

    I can easily do it using the following standalone html form:

    <form id="form_id" method="post" name="search" action="search.php">
    <select name="site" id="site">
    <option value="https://my.wordpress_site" selected>WordPress site</option>
    <option value="https://www.site1.com">site1</option>
    <option value="https://www.site2.com">site2</option>
    </select>
    <input type="text" value="" name="term" id="term" />
    <input type="submit" value="Submit">
    </form>

    I then pass the variables, “site” and “term” onto search.php which combines them and sends them on to the selected site to search, outside of WordPress, using:

    <?php header("Location: https://www.site1.com/?query=term"); ?>

    It works fine on its own. I am now trying to figure out how I could pull it into WordPress, so users could choose between searching the blog, or site 1, site 2, and so on.

    Digging around online and in the WordPress forum, I have found similar questions. It sounds like a common feature users are looking for.

    I’d be grateful for any assistance with this feature.

    Thanks.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    Redirecting the user is one thing. Getting remote search results to appear on your site is another thing entirely. The remote site should have an API of some sort that allows you to get results returned to your code in some structured format such as JSON or XML so your code can efficiently parse and organize the results in a way that’s compatible with your site.

    If each site has its own unique API, you might need a separate routine for every site that could possibly be searched.

    Thread Starter montgoc1

    (@montgoc1)

    Although it’s really crude, I am quite content to redirect the user to another site. I do not need the search results to appear in WordPress.

    How difficult is it to adjust the search box to redirect users to another site?

    Thanks.

    Moderator bcworkz

    (@bcworkz)

    The search box has its own form tag with an “action” attribute defining where to send the form submittal. You could have JavaScript update this value anytime a user changes the site selection field.

    Alternately, prevent the default submit action and have JS make the actual request based on the site selection field.

    Thread Starter montgoc1

    (@montgoc1)

    Thanks for your help. That makes sense. Where does the code for the search box reside?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Searching Exterior Sites from WordPress Search Box’ is closed to new replies.