希望你们中有人能帮助我。在我的wordpress页面上,当我使用搜索功能但没有结果时,我会收到以下消息:
注意:正在尝试获取/var/www/vhosts/tronicmart中非对象的属性。de/httpdocs/wp-content/themes/oceanwp/inc/helpers。php在线3392
注意:正在尝试获取/var/www/vhosts/tronicmart中非对象的属性。de/httpdocs/wp-content/themes/oceanwp/inc/helpers。php在线3400
注意:正在尝试获取/var/www/vhosts/tronicmart中非对象的属性。de/httpdocs/wp-content/themes/oceanwp/inc/helpers。php在线3406
if ( ! function_exists( \'oceanwp_excerpt\' ) ) {
function oceanwp_excerpt( $length = 30 ) {
    global $post;
    // Check for custom excerpt -->line 3392
    if ( has_excerpt( $post->ID ) ) {
        $output = $post->post_excerpt;
    }
    // No custom excerpt
    else {
        // Check for more tag and return content if it exists -->line 3400
        if ( strpos( $post->post_content, \'<!--more-->\' ) ) {
            $output = apply_filters( \'the_content\', get_the_content() );
        }
        // No more tag defined -->line 3406
        else {
            $output = wp_trim_words( strip_shortcodes( $post->post_content ), $length );
        }
    }
    return $output;
}
 }
 
                SO网友:Antti Koskinen
                如果没有搜索结果,那么可以预期$post 变量为空,并且其中没有要在if语句中使用的属性。
您可以通过添加if语句来确保$post 是3392线之前的样子。
if ( ! is_object($post) || ! is_a($post, \'WP_Post\') ) ) { 
return; 
}
或者懒惰的方式
if ( empty( $post->ID ) ) { 
return; 
}您可以随时使用var_dump 检查/调试变量,确保它们包含所需的内容。