Support Forums

The forums are closed and will be removed when we launch our new site.

Looking for support? You can access the support system via your account.

Forums Forums Search & Filter Pro Results displaying on index.php instead of search.php after first submission

Tagged: 

Viewing 7 posts - 1 through 7 (of 7 total)
  • dpolonsky
    #206794

    Hi,

    I’m having an issue where the results display on index.php. I have a search bar on my site that when they enter a search term, WordPress automatically takes them to search.php. In search.php is where I have my Search & Filter Pro shortcode. However, if I change the search term in the shortcode’s search bar, it takes me off of the search.php template.

    I noticed it when my styles went wonky (based on a body class) and a custom query (on pre_get_posts) from my theme isn’t kicking in anymore because part of my conditional checks for is_search(). When I error out is_home() in my theme for when I try to submit the form from the search.php file, when it loads, the error out says is_home is true.

    The HTML body classes on the page no longer include the “search search-results” classes that WP adds itself based on the template hierarchy. It now has “home” instead and I noticed there are parameters at the end of the search url.

    How do I fix it so it remains on the search.php template even if the user chooses filters or changes the search term to submit again?

    Here is how my “Display Results” tab is set in my plugin settings:

    Display results method: As an archive

    Template Options:
    Use custom template for results: Checked
    Enter the filename of the custom template: search.php
    Set a slug? (Left this empty)

    Ajax:
    Load results using Ajax? (I’ve tried this both checked and unchecked but it didn’t resolve the issue)
    Make searches bookmarkable: I had this checked but removed it when I thought it was interfering with the url and therefore where the results showed
    Only use Ajax on the results page? Checked
    Ajax Container: #search-results-wrapper

    dpolonsky
    #206797

    To clarify, the search bar that comes from the site is not from S&F Pro, it’s just the WP default search bar, but it will bring the user to search.php for the results – where the S&F shortcode form resides. It’s when searching in the S&F shortcode form that the results go to index.php. Thanks.

    Trevor Moderator
    #206804

    On the Advanced tab, did you try setting force is_search?

    dpolonsky
    #206854

    That did the trick! Thanks so much!

    Also – is there any reason why the search term isn’t already in the search form when landing on the search results? Looks like this is only an issue when I use my default WP search bar elsewhere on the site that takes me to the results the first time. If I add a search term in the shortcode form on the search results page – it keeps the search word in the field after submission.

    Trevor Moderator
    #206870

    You may need to perform a URL rewrite of the standard search. This post looks at one way to do this:

    https://support.searchandfilter.com/forums/topic/how-to-maintain-search-string-while-filtering/#post-205209

    dpolonsky
    #208110

    I managed to pull the term in by using the sf_input_object_pre hook so find the search field and check if the value was empty. On my site, the only way to get to the search results page is from the header search so they should always arrive with a search term. So by getting the term from $wp->query_vars['s'], it will fill it into the shortcode form before it renders the first time on the results page.

    I’m still having some funky issues though – like the logo on my site is a link to the homepage on every page that is NOT the homepage. But since is_home is now true on the search results page despite that I’m forcing the is_search from the plugin options, I had to edit my logo so it would be a link if it was search with is_search. So far so good. Thank you for all your patience. Much appreciated.

    Trevor Moderator
    #208127

    Great news. Is it OK to close this thread for now?

Viewing 7 posts - 1 through 7 (of 7 total)

The forum ‘Search & Filter Pro’ is closed to new topics and replies.