Archived topic
get property of non-object
12 replies · Started by Alain Aubry on November 29, 2018
Hi
I don’t visually see any problem, but when I enable “debug” I see 3 lines with the following texts:
Notice: Trying to get property of non-object in /home/…/wp-content/plugins/wordpress-seo/frontend/class-frontend.php on line 717
Notice: Trying to get property of non-object in /home/…/wp-content/plugins/wordpress-seo/frontend/class-frontend.php on line 720
Notice: Trying to get property of non-object in /home/…/wp-content/plugins/wordpress-seo/frontend/class-breadcrumbs.php on line 399
As these lines points to wordpress-seo, I opened a ticket at: https://wordpress.org/support/topic/get-property-of-non-object/
After following their suggestions I found the fault at my "GeneratePress Child Theme". It just happens in Author pages when the child theme is enabled, otherwise works fine.
I am bringing this here in order to find some suggestions to diagnose, how to find the faulty script. I have a big amount of functions and actions in my functions.php, many recommended here or in some other sources.
Thanks
Alain
Hi there,
Do you have any functions in your child theme? If so, can you share them?
Hi Tom
I have lots of functions...
They were tested individually before going live.
The only place where the word author is found is here (two places):
// GP Set CPT Image Positions
add_filter( 'option_generate_blog_settings', 'indigo_cpt_options' );
function indigo_cpt_options( $options ) {
if ( is_post_type_archive( array( 'actividade', 'colaborador', 'course' ) ) OR is_tax( array( 'grupo', 'tipo' ) ) OR is_search() ) {
$options[ 'masonry' ] = true;
$options[ 'infinite_scroll' ] = true;
$options[ 'post_image_padding' ] = false;
$options[ 'post_image_position' ] = 'post-image-above-header';
$options[ 'post_image_alignment' ] = 'post-image-aligned-center';
$options[ 'author' ] = false;
$options[ 'comments' ] = false;
}
if ( is_post_type_archive( 'evento' ) ) {
$options[ 'masonry' ] = false;
$options[ 'infinite_scroll' ] = true;
$options[ 'post_image' ] = true;
$options[ 'post_image_padding' ] = true;
$options[ 'post_image_position' ] = 'below-title';
$options[ 'post_image_alignment' ] = 'left';
$options[ 'author' ] = false;
$options[ 'comments' ] = false;
}
if ( is_singular( 'colaborador' ) ) {
$options[ 'single_post_image' ] = true;
$options[ 'single_post_image_padding' ] = true;
$options[ 'single_post_image_position' ] = 'below-title';
$options[ 'single_post_image_alignment' ] = 'left';
$options[ 'author' ] = false;
$options[ 'comments' ] = false;
}
return $options;
}
// End GP Set CPT Image Positions
and
// Insert Yoast WPSEO Breadcrumbs */
add_action( 'generate_before_main_content', 'indigo_breadcrumbs' );
function indigo_breadcrumbs() {
if ( function_exists( 'yoast_breadcrumb' ) && is_single() && 'lesson' !== get_post_type() ) : // && 'lesson' !== get_post_type() && ! is_author()
yoast_breadcrumb( '<div class="inside-article"><p id=”breadcrumbs”>', '</p></div>' );
endif;
}
// END Insert Yoast WPSEO Breadcrumbs */
This second one 'author' is in a comment...
Thanks
Alain
I am planning disabling all the "actions" one by one, as I did with the plugins.
That's a good idea - let me know if you can pinpoint the function :)
OK, I found the function that causing the problem, but it does not make any sense.
I am going the share the faulty function:
// Indigo Adjust Main Queries
add_action( 'pre_get_posts', 'indigo_adjust_queries' );
function indigo_adjust_queries( $query ) {
if ( !is_admin() && is_post_type_archive( 'actividade' ) && $query->is_main_query() ) :
$query->set( 'post_per_page', -1 );
$query->set( 'orderby', 'post_modified' );
$query->set( 'order', 'DESC' );
endif; // actividade
if ( !is_admin() && is_post_type_archive( 'colaborador' ) && $query->is_main_query() ) :
$query->set( 'post_per_page', -1 );
$query->set( 'orderby', array(
'relation' => 'AND',
array(
'orderby' => 'menu_order',
'order', 'ASC'
),
array(
'orderby' => 'post_title',
'order', 'ASC'
)
));
endif; // colaborador
if ( !is_admin() && is_post_type_archive( 'evento' ) && $query->is_main_query() ) :
$today = date('Ymd');
$query->set( 'post_per_page', -1 );
$query->set( 'post_type', 'evento' );
$query->set( 'meta_key', 'data_do_evento' );
$query->set( 'orderby', 'meta_value_num' );
$query->set( 'order', 'ASC' );
$query->set( 'meta_query', array(
array(
'key' => 'data_do_evento',
'compare' => '>=',
'value' => $today,
'type' => 'numeric'
)
));
endif; // evento
if ( !is_admin() && is_post_type_archive( 'course' ) && $query->is_main_query() ) :
$query->set( 'post_per_page', -1 );
$query->set( 'orderby', 'post_modified' );
$query->set( 'order', 'DESC' );
endif; // course
$term = single_term_title( '', false );
if ( $term ) :
if ( !is_admin() && is_tax( 'grupo' ) && $query->is_main_query() ) :
$query->set( 'post_per_page', -1 );
$query->set( 'post_type', 'colaborador' );
$query->set( 'orderby', 'menu_order' );
$query->set( 'order', 'ASC' );
$query->set( 'tax_query', array(
array(
'taxonomy' => 'grupo',
'field' => 'name',
'operator' => 'IN',
'terms' => $term
)
));
endif; // colaborador
if ( !is_admin() && is_tax( 'tipo' ) && $query->is_main_query() ) :
$query->set( 'post_per_page', -1 );
$query->set( 'post_type', 'actividade' );
$query->set( 'orderby', 'post_modified' );
$query->set( 'order', 'DESC' );
$query->set( 'tax_query', array(
array(
'taxonomy' => 'tipo',
'field' => 'name',
'operator' => 'IN',
'terms' => $term
)
));
endif; // actividade
endif; // terms
} // END indigo_adjust_queries
I will continue splitting this function into parts, maybe I can find it...
Thanks
Something is wrong here:
$term = single_term_title( '', false );
I'm not sure what would trigger that warning in Yoast SEO, unfortunately. Have you shared the problem function with them?
They closed my ticket as resolved previously, as the problem is located in my child theme I agreed in closing. I will share again.
It is shared here:
https://wordpress.org/support/topic/get-property-of-non-object/#post-10940723
They have an open ticket in Github:
https://github.com/Yoast/wordpress-seo/pull/10905
Hi Tom
You should read this:
https://wordpress.org/support/topic/get-property-of-non-object/#post-10940996
It seems he gave you a solution here: https://wordpress.org/support/topic/get-property-of-non-object/#post-10941663
Yes, the solution is working, I only tried local.
Thank you for being present and supportive...
Great to hear :)