在 WP 管理面板中,有带有“父级”下拉列表的“属性”元框。我需要更改排序参数并仅显示父帖子。如果我更改原生 WP 文件meta-boxes.php第621行,我可能会这样做。以下代码:
$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',
);
使用这一切都很完美。但我需要钩住它。我已经创建了 actiont 来执行此操作,但它不起作用:
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.
}
我做错了什么?