Created
September 14, 2018 11:10
-
-
Save morgyface/bac286aa7a3926c90a47b005d93f5bc8 to your computer and use it in GitHub Desktop.
WordPress | Checks to see if a post is a child, that is; does the post have 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 | |
| // Check if post has any parents | |
| function is_child($post_id) { | |
| $post = get_post($post_id); | |
| $parent = $post->post_parent; | |
| if( $parent != 0 ) { | |
| return true; | |
| } else { | |
| return false; | |
| } | |
| } | |
| ?> | |
| <?php | |
| // Example | |
| if( is_child( $post_id ) ) { | |
| echo 'I have a parent I am a child'; | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment