This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

Cannot override Search Results page

Cannot override Search Results page

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Cannot override Search Results page

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #57580
    cpunter_e8TMcpunter_e8TM
    Participant

    Hi,

    I have followed the doc here, but I cannot get it worked.
    https://documentation.ajaxsearchpro.com/behavior/results-page-override

    I’d like the flow like this: when users click or enter search on the default search forms (anywhere on site), instead of going to default search result page, they will be redirect to the custom search results page where I already put the ASP shortcode.
    https://www.hifi-advice.com/blog/prometheus/?page_id=42842

    Thanks in advance!

    Best,
    George

    #57581
    Ernest MarcinkoErnest Marcinko
    Keymaster

    Hi George,

    It is possible, but you will have to programmatically edit the default search forms to redirect to that URL. That is outside of the scope of Ajax Search Pro though, the default search forms are not controlled by the plugin.

    Because that I can’t guarantee anything as this is way beyond my support duties, but I’m still happy to help.

    The best way to do that is to edit the default search forms source code and add a hidden input with the page id and change the “s” input to “asp_s” to auto-trigger the search on your custom page.

    So this is the original header form:

    <form method="get" action="https://www.hifi-advice.com/blog/prometheus">
    	<input type="text" name="s" class="input-search font-1 active-true" placeholder="Search">
    	<input type="hidden" name="post_type" value="post">
    </form>

    And changing it to:

    <form method="get" action="https://www.hifi-advice.com/blog/prometheus">
    	<input type="text" name="asp_s" class="input-search font-1 active-true" placeholder="Search">
    	<input type="hidden" name="page_id" value="42842">
    </form>

    will do the trick.

    If it is not possible to change the source code for some reason, then using a javacscript code snippet could also work:

    document.querySelector('.cactus-form-header form')?.addEventListener('submit', function(e) {
      e.preventDefault();
      var s = encodeURIComponent(this.querySelector('input[name="s"]').value);
      window.location.href = '/blog/prometheus/?page_id=42842&asp_s=' + s;
    });

    However these heavily depends on implementation. You may also have to consult with the theme developer on how to change those parameters properly.

    #57584
    cpunter_e8TMcpunter_e8TM
    Participant

    Hi,

    Thanks for your quick support.

    Yes, if it requires additional code, I’ll find a way to implement it. However, in which scenario would the plugin’s feature called “results page override” as mentioned in the provided documentation be utilized?

    Best,
    George

    #57593
    Ernest MarcinkoErnest Marcinko
    Keymaster

    Hi George,

    So the results page override is a feature to replace the results on the WordPress search results page (aka site.com/?s=phrase), with the ones originating from Ajax Search Pro. When the override is enabled, the plugin will take over the search query, and replace the results with it’s own. It can’t change the layout/design (because that is a results page feature), it sends it’s own results to the results page for display.

    #57594
    cpunter_e8TMcpunter_e8TM
    Participant

    Ah,

    So just override the logic to return the results instead of appearance, right? The plugin is powerful but it’s still not easy to understand and configure. 🙁

    Best,

    #57595
    Ernest MarcinkoErnest Marcinko
    Keymaster

    Exactly – however there is an automatic replacemet feature as well, if the theme supports it. You can choose on the instances list which search bar you want Ajax Search Pro to replace the original theme search.

    This feature highly depends on the theme, if their search form is hard-coded and doesn’t use the get_search_form hook, then the only way to replace it is manually through the source files.
    That is also possible, after locating the source within a child theme. I think in your theme it is hard-coded into the header-navigation.php, it should be possible to add the PHP shortcode there.

    #57596
    cpunter_e8TMcpunter_e8TM
    Participant

    Thanks for your information. I will check how I should to implement the ASP for the site. You can close this ticket. Thanks again.

    Best,
    George

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.