wp_get_post_parent_id

函式
wp_get_post_parent_id ( $post = null )
引數
  • (int|WP_Post|null) $post Optional. Post ID or post object. Defaults to global $post.
    Required:
    Default: null
返回值
  • (int|false) Post parent ID (which can be 0 if there is no parent), or false if the post does not exist.
定義位置
相關方法
get_post_parentwp_get_post_catswp_get_post_revisionwp_get_post_revisionswp_get_term_taxonomy_parent_id
引入
3.1.0
棄用
-

wp_get_post_parent_id: 這個函式為一個給定的文章檢索父文章的ID。它接受一個文章的ID作為引數。

返回該文章的父級ID。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function wp_get_post_parent_id( $post = null ) {
$post = get_post( $post );
if ( ! $post || is_wp_error( $post ) ) {
return false;
}
return (int) $post->post_parent;
}
function wp_get_post_parent_id( $post = null ) { $post = get_post( $post ); if ( ! $post || is_wp_error( $post ) ) { return false; } return (int) $post->post_parent; }
function wp_get_post_parent_id( $post = null ) {
	$post = get_post( $post );

	if ( ! $post || is_wp_error( $post ) ) {
		return false;
	}

	return (int) $post->post_parent;
}

常見問題

FAQs
檢視更多 >