Cannot change items label of Association Field
Version
- Carbon Fields: 3.1.14
- WordPress: 5.2.3
- PHP: 7.1.3
Expected Behavior
Use the carbon_fields_association_field_item_label filter, to modify the label of the association items.
Default label should be the name of the sub-type/post-type, instead of "post".
Actual Behavior
Nothing is modified. Carbon Fields are using 'type' instead of 'label' in the format_post_option() method, to create the actual label of the item.
Container definition
//add_filter('carbon_fields_association_field_item_label', function ($label, $name, $id, $type, $subtype) {
// return 'New Label';
//}, 999, 5);
Steps to Reproduce the Problem
- Use the
carbon_fields_association_field_item_labeland return some value. Nothing is modified on the item.
Comments
It seems to me, that this is bug or maybe I have misunderstood the use of this filter. No matter what it could be quite handy, to be able to modify the item "label" from the default "post" to something else like the post-type. Especially when having mixed post-types in the same association.
I faced this bug too. I think there is a bug which carbon field is using $type['type'] as the second parameter for get_item_label(), which the second one should be the name of association field.
I tried to change label for a user association field from nicename to displayname with the following function. I did got the result when I var_dump() it, but the label doesn't change at all
add_filter('carbon_fields_association_field_item_label', function($label, $name, $id, $type, $subtype){
if($type === 'user'){
$label = get_user_by( 'id', $id )->data->display_name;
}
return $label;
}, 10, 5);
Hey Guys,
Thank you for pointing this out.
The issues has been fixed here -- 698578198d26c2d38dc941fc20dcf2f81f1d957b
By default, custom post types will show the post type label instead of "Post".
You can also change the label by using the carbon_fields_association_field_item_label filter