警告:尝试读取 null 上的属性“ID”

Warning: Attempt to read property "ID" on null

提问人:Uros Dioda Rakic 提问时间:11/16/2023 最后编辑:LoicTheAztecUros Dioda Rakic 更新时间:11/16/2023 访问量:64

问:

我收到此错误:

Warning: Attempt to read property "ID" on null in C:\Users\Uros\Local Sites\trendo\app\public\wp-includes\link-template.php on line 394

Warning: Attempt to read property "ID" on null in C:\Users\Uros\Local Sites\trendo\app\public\wp-includes\link-template.php on line 445

Warning: Attempt to read property "ID" on null in C:\Users\Uros\Local Sites\trendo\app\public\wp-includes\link-template.php on line 456

Warning: Attempt to read property "ID" on null in C:\Users\Uros\Local Sites\trendo\app\public\wp-includes\link-template.php on line 409

此错误出现在我列出所有产品的存档.php文件中。当我想访问没有产品的类别时,会出现错误,如果有产品,一切正常。谁能帮我解决这个问题?

function get_page_link( $post = false, $leavename = false, $sample = false ) {
    $post = get_post( $post );

    if ( 'page' === get_option( 'show_on_front' ) && get_option( 'page_on_front' ) == $post->ID ) {  <------394 line
        $link = home_url( '/' );
    } else {
        $link = _get_page_link( $post, $leavename, $sample );
    }
}

function _get_page_link( $post = false, $leavename = false, $sample = false ) {
    global $wp_rewrite;

    $post = get_post( $post );

    $force_plain_link = wp_force_plain_post_permalink( $post );

    $link = $wp_rewrite->get_page_permastruct();

    if ( ! empty( $link ) && ( ( isset( $post->post_status ) && ! $force_plain_link ) || $sample ) ) {
        if ( ! $leavename ) {
            $link = str_replace( '%pagename%', get_page_uri( $post ), $link );
        }

        $link = home_url( $link );
        $link = user_trailingslashit( $link, 'page' );
    } else {
        $link = home_url( '?page_id=' . $post->ID ); <---- 445 line
    }

    return apply_filters( '_get_page_link', $link, $post->ID ); <--- -456 line
}

function get_page_link( $post = false, $leavename = false, $sample = false ) {
    $post = get_post( $post );

    if ( 'page' === get_option( 'show_on_front' ) && get_option( 'page_on_front' ) == $post->ID ) {
        $link = home_url( '/' );
    } else {
        $link = _get_page_link( $post, $leavename, $sample );
    }

    /**
     * Filters the permalink for a page.
     *
     * @since 1.5.0
     *
     * @param string $link    The page's permalink.
     * @param int    $post_id The ID of the page.
     * @param bool   $sample  Is it a sample permalink.
     */
    return apply_filters( 'page_link', $link, $post->ID, $sample ); <----- 409 line
}
wordpress woocommerce

评论

2赞 LoicTheAztec 11/16/2023
您应该按照此处中的说明启用WP_DEBUG,因为提供的详细信息没有人可以通过魔法猜测事物......
0赞 Uros Dioda Rakic 11/16/2023
我编辑@Syntax_Error
2赞 LoicTheAztec 11/16/2023
因此,在某些情况下似乎没有定义变量(它是),因此当代码尝试使用 获取属性时,在这种情况下会抛出警告消息。没有人能凭着提供的详细信息猜到是什么导致了这个问题......这可能与另一个插件、您的主题或您添加的一些自定义代码有关......$postnullID$post->ID

答: 暂无答案