Last active
December 24, 2015 05:58
-
-
Save taishikato/6753529 to your computer and use it in GitHub Desktop.
WordPressの固定ページにおける親ページ判定関数
This file contains hidden or 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 get_root_page ( $cur_post, $cnt = 0 ) { | |
if ( $cnt > 100 ) { return false; } | |
$cnt++; | |
if ( $cur_post->post_parent == 0 ) { | |
$root_page = $cur_post; | |
} else { | |
$root_page = get_root_page( get_post( $cur_post->post_parent ), $cnt ); | |
} | |
return $root_page; | |
} | |
$root_page = get_root_page($post); | |
$root_id = $root_page->ID; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment