WordPress自定义元数据插件重新排序字段

时间:2013-11-08 23:15:10

标签: php wordpress plugins metadata field

我正在使用WordPress'Custom Metadata Plugin将元数据组添加到我正在处理的网站。

我想要做的是添加一个自定义字段,可以根据需要添加更多自定义字段,如下所示:the admin panel view of my custom fields

但是当我发布帖子时,它会混淆输入顺序,如下所示: when i enter data, it randomly reorders it.

这是我的代码。正在x_add_metadata_field函数底部创建多个字段,其中包含multiple=> true

function myfunction_x_init_cw_fields(){
  if( function_exists( 'x_add_metadata_field' ) && function_exists( 'x_add_metadata_group' ) ) {
$post_types = array( 'page' );
$args = array(
  'label' => 'Include Content Widgets', // Label for the group
  'context' => 'normal', // (post only)
  'priority' => 'default', // (post only)
  'autosave' => false //, // (post only) Should the group be saved in autosave? NOT IMPLEMENTED YET!
  //'exclude' => '', // posts#s to exclude
  //'include' => '', // posts#s to include
);
x_add_metadata_group( 'myfunction_cw_details', $post_types, $args );

x_add_metadata_field( 'myfunction_page_cw_field', $post_types, array(
  'group' => 'myfunction_cw_details', // the group name
  'description' => esc_html('Enter content widget slug under "content widgets"'),
  'label' => 'Content Widget Slugs',
  'multiple' => true
));
}
}

add_action( 'custom_metadata_manager_init_metadata', 'myfunction_x_init_cw_fields' );

基本上,我希望有人会说“嘿,有一个设置来订购文档中没有提到的结果。”

1 个答案:

答案 0 :(得分:0)

您是否尝试将这些添加到您的args中:

'orderby' => 'meta_value',
'order' => 'ASC' 

E.g

x_add_metadata_field( 'myfunction_page_cw_field', $post_types, array(
  'group' => 'myfunction_cw_details', // the group name
  'description' => esc_html('Enter content widget slug under "content widgets"'),
  'label' => 'Content Widget Slugs',
  'multiple' => true,
  'orderby' => 'meta_value',
  'order' => 'ASC' 
));