• Dear fellow WP devs,

    I have a very strange behavior at one of my client’s websites atm. We had to merge two websites which both had new entries in wp_posts table. Merging could be done using sql scripts. After the merge process finished, we discovered the default WP search functionality is not working properly anymore.

    No matter which theme we use (Twenty-Twenty-One, old custom theme in which the search functionality has worked before the merging, new custom theme), the search.php template which is present in all themes is never being loaded. Instead the default blog template (home page) is being loaded. There is one slight difference on the home page. The first displayed blogpost is being changed to a post which matches the search query result. Never came across this behavior.

    Another interesting fact is that the search template is indeed being loaded when I am logged in and have the WP customizer opened. But as soon as I close it and I send a search query request, only the homepage is being reloaded and not the search template.

    We also have a staging env where we still have the old website (before merging two website). On this page the theme and wp configs are identical as on prod and there the search functionality is working. WTF? I did DB diffs all day long and atm I have no idea what causes this behavior.

    Any support / advice is highly appreciated.

    Thanks and best
    Nina

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    The customizer preview loads content in a different manner than the normal site. While it confirms search can work and it’s unlikely the DB is corrupted, it doesn’t provide any clues to why normal search usage fails.

    Is the form making the proper HTTPS request? (like example.com/?s=foo) Verify through the browser’s network developer tool, the address bar is an unreliable indication.

    The template used is determined by which is_* query var is set to true. is_search should be set to get the search.php template. No match causes the default index.php template to be used. It’ll still only display pertinent query results. If you are getting all posts instead of search results, it’s likely there are invalid query vars which WP_Query would then ignore. If the “s” query var was properly requested but the query fails to return appropriate search results, it’s likely a plugin has inadvertently corrupted the query.

    Try deactivating all plugins. For good measure switch to Twenty Twenty-one theme as well. Search should function as expected now. Narrow down the cause of trouble by restoring your normal theme and plugins, one at time, until the problem returns.

Viewing 1 replies (of 1 total)
  • The topic ‘Search template is not loaded’ is closed to new replies.