At WP Admin panel there are “Attributes” metabox with “Parent” dropdown list.
I need to change sort parameters and show only parent posts.
I may do it if I change native WP file meta-boxes.php line 621. Following code:
$dropdown_args = array(
'post_type' => $post->post_type,
'exclude_tree' => $post->ID,
'selected' => $post->post_parent,
'name' => 'parent_id',
'show_option_none' => __('(no parent)'),
//Remove existing sort
//'sort_column' => 'menu_order, post_title',
'echo' => 0,
//Add my options
'parent' => 0,
'sort_order' => 'DESC',
'sort_column' => 'post_date',
);
Using this all work perfect. But i need to hook it. I have created actiont to do it, but it does not works:
add_action('page_attributes_meta_box', 'custome_page_attributes_meta_box');
function custome_page_attributes_meta_box($post) {
$post_type_object = get_post_type_object($post->post_type);
if ( $post_type_object->hierarchical ) {
$dropdown_args = array(
'post_type' => $post->post_type,
'exclude_tree' => $post->ID,
'selected' => $post->post_parent,
'name' => 'parent_id',
'show_option_none' => '(no parent)',
'echo' => 0,
'sort_order' => 'DESC',
'sort_column' => 'post_date',
'parent' => 0
);
$dropdown_args = apply_filters( 'page_attributes_dropdown_pages_args', $dropdown_args, $post );
$pages = wp_dropdown_pages( $dropdown_args );
if ( ! empty($pages) ) {
?>
<p><strong><?php _e('Parent') ?></strong></p>
<label class="screen-reader-text" for="parent_id"><?php _e('Parent') ?></label>
<?php echo $pages; ?>
<?php
} // end empty pages check
} // end hierarchical check.
}
What I am doing wrong?
You are trying to hook into an inexistant action.
In the core files, you have to look for
do_action
andapply_filters
.In this case, there’s one that’s exactly what you need:
I know this question is old. But I have found a simpler solution to keep all previous arguments and just show private posts: