Last active
August 26, 2017 13:27
-
-
Save jasondmoss/7344479 to your computer and use it in GitHub Desktop.
Whether a post is a child of a parent
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 | |
| /** | |
| * Whether a post is a child of a parent | |
| * | |
| * @param mixed $parent Page ID, slug or title | |
| * | |
| * @return boolean | |
| * @access public | |
| */ | |
| function isChild($parent = '') | |
| { | |
| global $post; | |
| $parent_obj = get_page($post->post_parent, ARRAY_A); | |
| $parent = (string) $parent; | |
| $parent_array = (array) $parent; | |
| if (in_array((string) $parent_obj['ID'], $parent_array) | |
| || in_array((string) $parent_obj['post_title'], $parent_array) | |
| || in_array((string) $parent_obj['post_name'], $parent_array) | |
| ) { | |
| return true; | |
| } | |
| return false; | |
| } | |
| /* <> */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment