July 24, 2014
A handy WordPress function to allow you to filter by child pages for great functionality. Please see reference and author here. Function and simple example usage. Please see website of Kevin Leary for greater functionality and more complex usage.
<?php function is_child( $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 ) ) { return true; } elseif ( in_array( (string) $parent_obj['post_title'], $parent_array ) ) { return true; } elseif ( in_array( (string) $parent_obj['post_name'], $parent_array ) ) { return true; } else { return false; } } if ( is_child(221) ); ?>