WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Google Custom Search -- Close to fixing it (2 posts)

  1. CallUp
    Member
    Posted 3 years ago #

    I've been working on integrating this Google Custom Search into my site on and off over the last couple days, and I think I've finally figured it out.

    I'm hoping someone will have a good idea for the best possible solution.

    When the search results are generated from the Google search box located at the top of my home page the results are displayed accurately on my page (named 'search'):
    http://localhost/search ...

    When the search results are generated from the Google search box located at the top of my category pages (i.e. category) the 404 Error is generated on:
    http://localhost/category/politics/search ...

    My 'search' page, to display the search results -- which I created from my dashboard -- can only be found at http://localhost/search.

    That's why I'm getting the 404 error. It's looking for my 'search' page at: localhost/category/politics/search, and it's not there.

    So, the problem was that when Google asked me to name the page for search results, it said not to include the url -- that a single page name like "search" would be appended at the end of the url automatically.

    I can hardcode the entire static url on my search form: <form action="http://www.website.com/search" ... instead of <form action="search" ... but I'd like to find a dynamically generated url that can work on both my local environment testing site and my main site.

    What would you advise?

    I understand there's document.location.host in javascript. Perhaps something like <form action=document.location.host + "/search" ??????

    Any ideas on the very best way to achieve this so that it will work well on all browsers?

    I hope that someone will please answer me, this time.

  2. CallUp
    Member
    Posted 3 years ago #

    This php option seems to work, so I guess I'll stick with it:

    <form action="<?php bloginfo('url'); ?>/search" id="cse-search-box">

Topic Closed

This topic has been closed to new replies.

About this Topic