
How to Fix Kirby’s filterBy on null PHP Fatal Error.
Not too long ago, I received a frantic call from a recently migrated from WordPress to Kirby customer. All was going well until they encountered the frustrating “PHP Fatal error: Uncaught Error: Call to a member function filterBy() on null” error.
I suppose that if you’re reading this blog post, chances are that you, too, are in dire need of getting your Kirby website back online, right?
Well, I’ve got good news for you. I’ve got just the solution for you!
Whether you’re a tech-savvy user or a non-tech person, I’ll guide you through the easy-to-follow steps to fix this error in this tutorial.
First things first, make sure you locate which files this error is occurring in. For this given customer, the error message suggested that the “filterBy()” function is being called on a null value in the Kirby home.php and article.php files.
Now for the fix. It involves replacing the deprecated “visible()” method with the “listed()” method in both the home.php and article.php files. To do so, follow these steps:
- Edit home.php: Inside the home.php file, locate the following code snippet:
<?PHP $article = $site->index() ->visible() ->filterBy('intendedTemplate', 'article') ->sortBy('date', 'desc') ->first() ?>
Replace the “visible()” method with “listed()”:
<?PHP $article = $site->index() ->listed() ->filterBy('intendedTemplate', 'article') ->sortBy('date', 'desc') ->first() ?>
- Edit article.php: Inside the article.php file, locate the following code snippet:
<?PHP $articles = $site->index() ->visible() ->filterBy('intendedTemplate', 'article') ->sortBy('date', 'desc'); $index = $articles->indexOf($page); $last = $articles->count() - 1; $prev = $index > 0 ? $articles->nth($index - 1) : null; $next = $index < $last ? $articles->nth($index + 1) : null; ?>
Replace the “visible()” method with “listed()”:
<?PHP $articles = $site->index() ->listed() ->filterBy('intendedTemplate', 'article') ->sortBy('date', 'desc'); $index = $articles->indexOf($page); $last = $articles->count() - 1; $prev = $index > 0 ? $articles->nth($index - 1) : null; $next = $index < $last ? $articles->nth($index + 1) : null; ?>
Going from visible() to listed().
By replacing the deprecated “visible()” method with the “listed()” method in the home.php and article.php files, you can quickly fix the “filterBy on null” PHP Fatal Error in Kirby.
Remember to save the modified files and refresh your website to see the changes take effect.
If you’re unsure about making these changes, don’t hesitate to seek assistance from a developer or consult the Kirby documentation. And if you run into any challenges implementing this fix, please don’t hesitate to comment below.
Thanks, and that’s all for now!
Leave a Comment