我创建了一个分类法并将其附加到附件或媒体。
我正在使用高级自定义字段添加一个显示为checkbox group的分类字段。它将字段正确地添加到网格视图和列表视图中的附件页。
在列表视图中,字段会正确更新,但在网格视图中,它只保存最后单击的复选框。这是由某种onclick函数引起的,该函数在单击每个复选框时激发adminajax。因此,它只发送点击框的值。我试图找到一种方法来改变js函数,使之成为checkbox groups和multi-select。
功能:保存
文件:media-views.min.js
function cptui_register_my_taxes() {
$labels = array(
"name" => __( "Image Tags", "" ),
"singular_name" => __( "Image Tag", "" ),
);
$args = array(
"label" => __( "Image Tags", "" ),
"labels" => $labels,
"public" => true,
"hierarchical" => false,
"label" => "Image Tags",
"show_ui" => true,
"show_in_menu" => true,
"show_in_nav_menus" => false,
"query_var" => true,
"rewrite" => false,
"show_admin_column" => false,
"show_in_rest" => false,
"rest_base" => "imagetags",
"show_in_quick_edit" => false,
);
register_taxonomy( "imagetags", array( "attachment" ), $args );
}
add_action( 'init', 'cptui_register_my_taxes' );
自定义字段:
if( function_exists('acf_add_local_field_group') ):
acf_add_local_field_group(array(
'key' => 'group_5bc3f242c39e3',
'title' => 'Gallery - Image Tags',
'fields' => array(
array(
'key' => 'field_5bc3f249f009c',
'label' => 'Image Tags',
'name' => 'new_image_tags',
'type' => 'taxonomy',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'taxonomy' => 'imagetags',
'field_type' => 'checkbox',
'add_term' => 1,
'save_terms' => 1,
'load_terms' => 1,
'return_format' => 'id',
'multiple' => 0,
'allow_null' => 0,
),
),
'location' => array(
array(
array(
'param' => 'attachment',
'operator' => '==',
'value' => 'all',
),
),
),
'menu_order' => 0,
'position' => 'normal',
'style' => 'default',
'label_placement' => 'top',
'instruction_placement' => 'label',
'hide_on_screen' => '',
'active' => 1,
'description' => '',
));
endif;
如果需要,还可以删除默认的分类字段,并使用以下代码。它不会影响代码,但会删除文本字段:
// Remove taxonomy from the attachment pages so the acf taxonomy can work
add_action( 'admin_menu', function (){ remove_meta_box('imagetagsdiv', 'attachment', 'side' ); } );
// Add this in to remove it from the popup editor
add_filter( 'attachment_fields_to_edit', function( $fields ){
unset($fields['imagetags']);
return $fields;
} );
发现问题
现在要找到解决办法
_.each( this.$el.serializeArray(), function( pair ) {
data[ pair.name ] = pair.value;
});
看起来他们使用此代码是为了防止重复,但实际上它删除了可以作为数组提交的所有内容。
注意:这是WP默认加载.min版本的完整文件