Archived topic
PHP Notices
19 replies · Started by Kim on December 2, 2019
Hi there, I just saw in the log that we get a bunch of those notices:
[03-Dec-2019 05:01:43 UTC] PHP Notice: Trying to get property 'ID' of non-object in /home/wp/disk/wordpress/wp-content/plugins/gp-premium/elements/class-hooks.php(180) : eval()'d code on line 2
[03-Dec-2019 05:01:43 UTC] PHP Notice: Undefined variable: post in /home/wp/disk/wordpress/wp-content/plugins/gp-premium/elements/class-hooks.php(180) : eval()'d code on line 2
Is this something to worry about? Anything I can do?
Many thanks in advance!
Hi there,
do you have any PHP functions in the GP Hooks Element?
Yes, I do. I think the issue is coming from this one:
<div class="wpsp-related-posts grid-container">
<h3>Das könnte Sie auch interessieren</h3>
<?php
if ( is_single() ) {
$cats = get_the_category();
$cat = $cats[0];
} else {
$cat = get_category( get_query_var( 'cat' ) );
}
$cat_slug = $cat->slug;
$list = get_page_by_title( 'related', 'OBJECT', 'wp_show_posts' );
wpsp_display( $list->ID, 'tax_term="' . $cat_slug . '"' );
?>
</div>
I use it to show related posts at the single blog pages. It's from the forum.
...or this one:
<?php
$terms = get_the_terms( $post->ID, 'product_cat' );
if ( $terms && ! is_wp_error( $terms ) ) :
if ( ! empty( $terms ) ) {
echo '<span class="woo-custom-category">' . $terms[0]->name . '</span>';
}?>
<?php endif;?>
It's used to display the Categories of a product on archive pages.
I would think the second one is the issue - simplest way is to Quick Edit the element and Save as Draft and see if the notice disappears.
Yes, the second one is causing the issue. Do you have any clue what could be the reason? It's from this post:
https://generatepress.com/forums/topic/woocommerce-display-category-name-above-product-titel/
Can you try changing this line:
if ( ! empty( $terms ) ) {
for:
if ( isset( $terms ) ) {
Hi David, unfortunately this doesn't solve the issue. Do you have another idea?
Can you try replacing this:
wpsp_display( $list->ID, 'tax_term="' . $cat_slug . '"' );
With this:
if ( is_object( $list ) ) {
wpsp_display( $list->ID, 'tax_term="' . $cat_slug . '"' );
}
I'm not seeing a $post variable (as per the second notice) - maybe a different hook?
Hi Tom, I've tested again and it is definitely coming from this one:
<?php
$terms = get_the_terms( $post->ID, 'product_cat' );
if ( $terms && ! is_wp_error( $terms ) ) :
if ( isset( $terms ) ) {
echo '<span class="woo-custom-category">' . $terms[0]->name . '</span>';
}?>
<?php endif;?>
So there you're using $post, but it's not defined.
You can do this instead:
<?php
$terms = get_the_terms( get_the_ID(), 'product_cat' );
if ( $terms && ! is_wp_error( $terms ) ) :
if ( isset( $terms ) ) {
echo '<span class="woo-custom-category">' . $terms[0]->name . '</span>';
}?>
<?php endif;?>
Thank very much your for the fix :-)
Sorry for asking again. This is another issue I just saw:
PHP message: PHP Warning: array_key_exists() expects parameter 2 to be array, bool given in /home/wp/disk/wordpress/wp-content/plugins/gp-premium/typography/functions/migration.php on line 170
Is it Theme-related or a Hosting issue?
Best regards!
Hmm, I'm assuming it's a hosting issue as no one else is experiencing that issue. Parameter 2 in that case should definitely be an array.
Are you using the generate_number_of_fonts anywhere?
No, actually this one is not in use