Created
August 23, 2018 09:58
-
-
Save Inzman/c63baa0a7094925bdc2434d7d843c9e4 to your computer and use it in GitHub Desktop.
Determine if a WordPress post or page has children
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
| function has_children() { | |
| global $post; | |
| return count( get_posts( array('post_parent' => $post->ID, 'post_type' => $post->post_type) ) ); | |
| } | |
| if ( has_children() ) { | |
| // do something if this item has children | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment