Can you provide more context for when this happens? switch_to_blog()
is only defined in multisite context, but that line should only run when a post has a defined blog ID, which only happens in multisite. Is this a multisite installation?
Hi, it is a singlesite installation and it has always been. I was not doing anything with the website, not clicking any admin things. I have just noticed it in the logs.
Maybe it is good to check if the function exists as the actual verification whether it is a multisite?
Well, it’s already doing that: it’s checking for $post->blog_id
, which Relevanssi only sets in multisite context.
Is this just a random single error message, or are there lots of these? Can you figure out what the user has been doing to trigger this?
It happens several times a day at different hours. Seems quite random.
The query is the search, like “GET /?s=Chleb HTTP/2.0”.
And indeed – I have just noticed that the search is totally broken. When you search for anything, you get a critical error message. Just browsed all the logs and the earliest entry I see is dated on 31st Mar 2023. Does this relate to one of the release dates?
Version 4.18.4 was released at the end of March. It was a minor update that added one filter hook and disabled Relevanssi searches in RSS feeds.
Have you tried disabling other plugins? If something else sets the $post->blog_id
attribute, that would break Relevanssi on a single-site installation. Relevanssi doesn’t do it unless it’s a multisite search, but something else can set it, and it would break Relevanssi.
I’ll throw in function_exists()
checks in Relevanssi to avoid this in the future, but that’ll be in the next version. Meanwhile, figuring out what sets the blog id in the posts would help fix this.
I have disabled all the other plugins and the issue remains. If I search for something that doesn’t exist, I get a normal page saying that it wasn’t found. When I search for something that exists, I get critical error.
I did:
function relevanssi_add_excerpt( &$post, $query ) {
if ( isset( $post->blog_id ) && function_exists( 'switch_to_blog' ) ) {
switch_to_blog( $post->blog_id );
}
and the same around restore_current_blog and it seems it helped. I would appreciate such entries in the next update, but no rush with it.
No idea what is wrong with my site.
Thank you for your help.
And btw – how do I modify what is displayed when nothing is found? I would like to add some text with links but I am unable to find where I can do that.
Ah, I think I found it. Two plugins didn’t get disabled (I think I misclicked – instead clicking twice deactivate, I deactivated and activated one of them) and one of them has a code:
$blog_id = get_current_blog_id();
It is the top-10 plugin (https://wordpress.org/plugins/top-10/) and I guess it is the culprit.
Anyway, appreciate the double check in future versions.
Nope, that’s not the one… that’s normal variable use, and doesn’t touch the post objects Relevanssi sees.
But yeah, future versions will not have this problem, I’ve guaranteed that.