Fatal Error if empty category

I’m using the events manager plugin and get a fatal error if i want to show a category from the events if they are no elements present.

[30-Jul-2021 12:09:05 UTC] PHP Notice:  Trying to get property 'post_type' of non-object in /home/domains/(domainname).at-2104/public/htdocs/wp-content/themes/pro-child/func_cpt.php on line 263
[30-Jul-2021 12:09:05 UTC] PHP Fatal error:  Uncaught Exception: Unable to load content from post. in /home/domains/(domainname).at-2104/public/htdocs/wp-content/themes/pro/cornerstone/includes/classes/content/class-content.php:54
Stack trace:
#0 /home/domains/(domainname).at-2104/public/htdocs/wp-content/themes/pro/cornerstone/includes/classes/content/class-content.php(25): Cornerstone_Content->load_from_post(NULL)
#1 /home/domains/(domainname).at-2104/public/htdocs/wp-content/themes/pro/cornerstone/includes/classes/elements/class-element-front-end.php(374): Cornerstone_Content->__construct(0)
#2 /home/domains/(domainname).at-2104/public/htdocs/wp-content/themes/pro/cornerstone/includes/classes/elements/class-element-front-end.php(125): Cornerstone_Element_Front_End->get_content(0)
#3 /home/domains/(domainname).at-2104/public/htdocs/wp-includes/class-wp-hook.php(301): Cornerstone_Element_Front_End->post_loaded()
#4 /home/domains/(domainname).at-2104/public/htdocs/wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters(NULL, Array)
#5 /home/dom in /home/domains/(domainname).at-2104/public/htdocs/wp-content/themes/pro/cornerstone/includes/classes/content/class-content.php on line 54

Categories:

Bildschirmfoto 2021-07-30 um 14.19.15

Not empty event categroies like “auffuehrung” or “intern” shown correctly

Bildschirmfoto 2021-07-30 um 14.18.45

Is it not possible to subdue the fatal error and show simply nothing?

Hi @Regnalf,

It seems that problem with the 3rd Party plugin which is outside the scope of our theme support. I would suggest you contact the Plugin Author on this.

Thanks

My question is not to fix a 3rd party plugin!!! The error is thrown by cornerstone!!

And again, is it realy neccessary to thrown a FATAL Error if unable to load post!! This could be done with empty output and a log in backend

Hi @Regnalf,

Sorry for any confussion, but it seems that the issue coming from the func_cpt.php in your child theme.

If you are using the said plugin to show the category that does not have any event, the exceptions on the empty category may not be handled properly. As the code is written into a 3rd Party plugin, you need to contact the Author on this.

On the other hand, I would request you activate any default theme like TwentyTwenty and check if that issue exists. If activating the default theme resolves the issue, please provide login credentials for your site in a secure note to examine it further, including:

– WordPress Site URL & Login URL
– WordPress Admin username/password

To create a secure note, click the key icon underneath any of your posts.

Thanks

Hi, as i mentioned before, your’e not responsible for 3rd party issues, and i’ve contacted the plugin developer anyway. the php notice from my func_cpt.php also falls in this issue, because the global $post is NULL.

If added a condition on line 263 to not create this PHP notice.

Bildschirmfoto 2021-07-30 um 18.52.46

The reason why i ask is, is it realy neccessary to produce a PHP Fatal error? Maybe there are reasons i don’t know. But a Fatal Error is allways a heavy impact on user experience. This could happen with other plugins too. So, if there is a way just to put out nothing instead of an php fatal error is allways better.
Maybe with WP Debug is true you could throw a message!

Hello @Regnalf,

The errors are good on the staging server not on the production server so that you can check ad fix the code issue easily. It is always a good practice to add any code modification, plugin test, theme update, and WordPress Core update on the staging server so that the live site doesn’t get affected by any errors.

To hide the PHP errors and warnings please have a look at this article to learn more about how to turn off the PHP errors.

Hope it helps
Thanks

I know the debug settings in wordpress, but a fatal error is the termination of the script if not catched, no matter if there is an error shown or not!

Hello @Regnalf,

Can you please temporarily remove your custom PHP function or at least switch to the parent theme to see if the fatal error will occur when there are no posts in your category? To better assist you with your issue, kindly provide us access to your site so that we can check your settings. Please create a secure note with the following info:
– Link to your site
– WP login URL
– WP username
– WP password
– WP Administrator Role
- Confirmation that we can access and make changes to your site

To know how to create a secure note, please check this out: How The Forum Works

Thank you in advance.

Thx again ruenel for your offer, but i actually know wehre this issue is coming from. It is in events manager, so the global $post should not be NULL., and the depending settings are in this plugin.

I realy just wanna point to the fact that a fatal error is thrown if this happens.

Hello @Regnalf,

To prevent the Fatal Error message “PHP Fatal error: Uncaught Exception: Unable to load content from post”, you must have a safeguard in your custom PHP code that it will only do something if the post is not null. You may need a loop just like in this example from the codex:

<?php if ( have_posts() ) : ?>
	<?php while ( have_posts() ) : the_post(); ?>    
	<!-- do stuff ... -->
	<?php endwhile; ?>
<?php endif; ?>

Please note that custom coding is outside the scope of our support. Issues that might arise from the use of custom code and further enhancements should be directed to a third-party developer.

Best Regards.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.