get_post_parent

函式
get_post_parent ( $post = null )
引數
  • (int|WP_Post|null) $post Optional. Post ID or WP_Post object. Default is global $post.
    Required:
    Default: null
返回值
  • (WP_Post|null) Parent post object, or null if there isn't one.
定義位置
相關方法
wp_get_post_parent_idhas_post_parentget_post_metaget_postdataget_post_format
引入
5.7.0
棄用
-

get_post_parent: 這個WordPress函式檢索當前文章的父文章的ID。如果當前文章沒有父文章或根本就不是一個文章,它將返回0。

為給定的文章檢索父職位物件。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function get_post_parent( $post = null ) {
$wp_post = get_post( $post );
return ! empty( $wp_post->post_parent ) ? get_post( $wp_post->post_parent ) : null;
}
function get_post_parent( $post = null ) { $wp_post = get_post( $post ); return ! empty( $wp_post->post_parent ) ? get_post( $wp_post->post_parent ) : null; }
function get_post_parent( $post = null ) {
	$wp_post = get_post( $post );
	return ! empty( $wp_post->post_parent ) ? get_post( $wp_post->post_parent ) : null;
}

常見問題

FAQs
檢視更多 >