Skip to content

Instantly share code, notes, and snippets.

@taishikato
Last active December 24, 2015 05:58
Show Gist options
  • Save taishikato/6753529 to your computer and use it in GitHub Desktop.
Save taishikato/6753529 to your computer and use it in GitHub Desktop.
WordPressの固定ページにおける親ページ判定関数
<?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