提问人:Uros Dioda Rakic 提问时间:11/16/2023 最后编辑:LoicTheAztecUros Dioda Rakic 更新时间:11/16/2023 访问量:64
警告:尝试读取 null 上的属性“ID”
Warning: Attempt to read property "ID" on null
问:
我收到此错误:
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
}
答: 暂无答案
评论
$post
null
ID
$post->ID