Last active
December 17, 2015 01:49
-
-
Save torounit/5531273 to your computer and use it in GitHub Desktop.
WordPressの階層のある投稿タイプで、最上位の親投稿のIDを返す。階層の無い投稿タイプの場合 falseを返す。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function current_hierarchical() { | |
global $post; | |
$post_type_object = get_post_type_object( get_post_type() ); | |
if ( $post_type_object->hierarchical ) { | |
if ( $post->post_parent ) { // is child page | |
$ancestors = get_post_ancestors( $post->ID ); | |
$root_ID = array_pop( $ancestors ); | |
} | |
else { // is root page | |
$root_ID = $post->ID; | |
} | |
return $root_ID; | |
} | |
return false; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment