Created
April 8, 2016 14:58
-
-
Save Jany-M/32e327d6c6a0eac149a83360fc8bb010 to your computer and use it in GitHub Desktop.
[WordPress] Display Post or Page Children in custom MetaBox
This file contains 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 | |
// This requires that your post type is hierarchical obviously (like Pages) | |
// Display all children of this post/page in a custom metabox below title | |
function display_msg_for_parents( $post ) { | |
$children = get_pages(array('child_of' => $post->ID, 'post_type' => get_post_type($post->ID),)); | |
if(!empty($children)) { ?> | |
<div class="rp_children postbox"> | |
<button class="handlediv button-link" aria-expanded="true" type="button"> | |
<span class="screen-reader-text">Toggle panel: Children</span> | |
<span class="toggle-indicator" aria-hidden="true"></span> | |
</button> | |
<h2 class="hndle ui-sortable-handle"> | |
<span>Children</span> | |
</h2> | |
<div class="inside"> | |
<p>This Post has the following children:</p> | |
<ul> | |
<?php foreach($children as $child) { | |
echo '<li><a href="'.get_edit_post_link($child->ID).'" target="_blank">'.$child->post_title.'</a></li>'; | |
} ?> | |
</ul> | |
</div> | |
</div> | |
<?php } | |
wp_reset_postdata(); | |
} | |
add_action( 'edit_form_after_title', 'display_msg_for_parents' ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment