This was found to be an issue with taxonomy relationship fields associated with users.
It's not yet known whether the issue also applies to relationship fields from or to other object types or single-select fields.
It's also notable that when adding fields to a user, a field key that is the same as a taxonomy key is allowed; this is not allowed on post types. While this did not seem to be the cause of the issue, as the tests check fields with two different names, it is confusing.
function terms_from_taxonomy_relationship_magic_tag( $value ) {
ob_start();
var_dump( $value );
return str_replace( PHP_EOL, '', ob_get_clean() );
}
Extensive unit tests.
It's a LocalWP multisite on WP 6.3.1 with no other plugins active.
{
"@meta": {
"version": "2.9.19",
"build": 1693599594
},
"settings": {
"types_only": "0",
"watch_changed_fields": "0",
"metadata_integration": "1",
"metadata_override_get": "0",
"media_modal_fields": "0",
"session_auto_start": "0",
"wisdom_opt_out": "1"
},
"pods": [
{
"name": "page",
"id": 19,
"label": "Page",
"description": "",
"type": "post_type",
"storage": "meta",
"object": "page",
"_migrated_28": "1",
"groups": [
{
"name": "more_fields",
"id": 20,
"label": "More Fields",
"description": "",
"weight": 0,
"fields": []
}
]
},
{
"name": "test_post",
"id": 7,
"label": "Test Posts",
"description": "",
"type": "post_type",
"storage": "meta",
"label_singular": "Test Post",
"public": "1",
"show_ui": "1",
"rest_enable": "1",
"supports_title": "1",
"supports_editor": "1",
"_migrated_28": "1",
"built_in_taxonomies_test_taxonomy": "1",
"groups": [
{
"name": "more_fields",
"id": 8,
"label": "More Fields",
"description": "",
"weight": 0,
"fields": []
}
]
},
{
"name": "test_taxonomy",
"id": 5,
"label": "Test Taxonomy Terms",
"description": "",
"type": "taxonomy",
"storage": "meta",
"label_singular": "Test Taxonomy",
"public": "1",
"show_ui": "1",
"hierarchical": "1",
"rest_enable": "1",
"_migrated_28": "1",
"built_in_post_types_test_post": "1",
"groups": [
{
"name": "more_fields",
"id": 6,
"label": "More Fields",
"description": "",
"weight": 0,
"fields": []
}
]
},
{
"name": "user",
"id": 9,
"label": "User",
"description": "",
"type": "user",
"storage": "meta",
"object": "user",
"_migrated_28": "1",
"required": "0",
"required_help_boolean": "0",
"groups": [
{
"name": "more_fields",
"id": 10,
"label": "More Fields",
"description": "",
"weight": 0,
"fields": [
{
"name": "test_taxonomy",
"id": 11,
"label": "Test Taxonomy",
"description": "",
"weight": 0,
"type": "pick",
"pick_object": "taxonomy",
"pick_val": "test_taxonomy",
"sister_id": "-- Select One --",
"pick_table": "-- Select One --",
"required": "0",
"required_help_boolean": "0",
"pick_format_type": "multi",
"pick_format_single": "dropdown",
"pick_format_single_help": "0",
"pick_format_multi": "list",
"pick_format_multi_help": "0",
"pick_display_format_multi": "default",
"pick_display_format_separator": ", ",
"pick_allow_add_new": "1",
"pick_taggable": "0",
"pick_show_icon": "1",
"pick_show_edit_link": "1",
"pick_show_view_link": "1",
"pick_limit": "0",
"pick_user_role": "Administrator",
"pick_post_status": "publish",
"pick_post_author": "0",
"repeatable": "0",
"repeatable_format": "default",
"roles_allowed": "administrator",
"rest_pick_response": "array",
"rest_pick_depth": "1"
},
{
"name": "rel_test_taxonomy",
"id": 12,
"label": "Rel Test Taxonomy",
"description": "",
"weight": 1,
"type": "pick",
"pick_object": "taxonomy",
"sister_id": "-- Select One --",
"pick_table": "-- Select One --",
"required": "0",
"required_help_boolean": "0",
"pick_format_type": "multi",
"pick_format_single": "dropdown",
"pick_format_single_help": "0",
"pick_format_multi": "list",
"pick_format_multi_help": "0",
"pick_display_format_multi": "default",
"pick_display_format_separator": ", ",
"pick_allow_add_new": "1",
"pick_taggable": "0",
"pick_show_icon": "1",
"pick_show_edit_link": "1",
"pick_show_view_link": "1",
"pick_limit": "0",
"pick_user_role": "Administrator",
"pick_post_status": "publish",
"pick_post_author": "0",
"repeatable": "0",
"repeatable_format": "default",
"roles_allowed": "administrator",
"rest_pick_response": "array",
"rest_pick_depth": "1",
"pick_val": "test_taxonomy"
}
]
}
]
}
]
}
Description
Magic tags for
{@user.field}multi-select relationship taxonomy fields have inconsistent output and passed values to helper functions.If multiple terms are assigned to the field:
{@user.field}outputs only the first term, and it's the Term ID.{@user.field,helper_function}passes false to the helper.{@field}passes a formatted string of Term Names with "and".{@field,helper_function}passes an array of term arrays.This was found to be an issue with taxonomy relationship fields associated with users.
It's not yet known whether the issue also applies to relationship fields from or to other object types or single-select fields.
Not included in the example, but also problematic, are
{@user.field.term_id}and{@user.field.term_id,helper}It's also notable that when adding fields to a user, a field key that is the same as a taxonomy key is allowed; this is not allowed on post types. While this did not seem to be the cause of the issue, as the tests check fields with two different names, it is confusing.
Originally reported in this thread where the field names and taxonomy names are in a mix of German and English, changing through the course of the conversation: https://wordpress.org/support/topic/compare-cpt-taxonomy-to-users-relationship-field/ . A PHP approach to expected behavior was provided on page 2: https://wordpress.org/support/topic/compare-cpt-taxonomy-to-users-relationship-field/page/2/#post-17019774
Version
2.9.19
Testing Instructions
Screenshots / Screencast
Term 2isterm_id4.Term 3isterm_id5.It's also notable that in the
var_dump()s of the term arrays,term_id,term_taxonomy_id,parent,count,term_group,object_id,term_order, andpod_item_idare all of typestring, whileintegerwould most likely be appropriate.Possible Workaround
Extensive unit tests.
Site Health Information
It's a LocalWP multisite on WP 6.3.1 with no other plugins active.
Pods Package
{ "@meta": { "version": "2.9.19", "build": 1693599594 }, "settings": { "types_only": "0", "watch_changed_fields": "0", "metadata_integration": "1", "metadata_override_get": "0", "media_modal_fields": "0", "session_auto_start": "0", "wisdom_opt_out": "1" }, "pods": [ { "name": "page", "id": 19, "label": "Page", "description": "", "type": "post_type", "storage": "meta", "object": "page", "_migrated_28": "1", "groups": [ { "name": "more_fields", "id": 20, "label": "More Fields", "description": "", "weight": 0, "fields": [] } ] }, { "name": "test_post", "id": 7, "label": "Test Posts", "description": "", "type": "post_type", "storage": "meta", "label_singular": "Test Post", "public": "1", "show_ui": "1", "rest_enable": "1", "supports_title": "1", "supports_editor": "1", "_migrated_28": "1", "built_in_taxonomies_test_taxonomy": "1", "groups": [ { "name": "more_fields", "id": 8, "label": "More Fields", "description": "", "weight": 0, "fields": [] } ] }, { "name": "test_taxonomy", "id": 5, "label": "Test Taxonomy Terms", "description": "", "type": "taxonomy", "storage": "meta", "label_singular": "Test Taxonomy", "public": "1", "show_ui": "1", "hierarchical": "1", "rest_enable": "1", "_migrated_28": "1", "built_in_post_types_test_post": "1", "groups": [ { "name": "more_fields", "id": 6, "label": "More Fields", "description": "", "weight": 0, "fields": [] } ] }, { "name": "user", "id": 9, "label": "User", "description": "", "type": "user", "storage": "meta", "object": "user", "_migrated_28": "1", "required": "0", "required_help_boolean": "0", "groups": [ { "name": "more_fields", "id": 10, "label": "More Fields", "description": "", "weight": 0, "fields": [ { "name": "test_taxonomy", "id": 11, "label": "Test Taxonomy", "description": "", "weight": 0, "type": "pick", "pick_object": "taxonomy", "pick_val": "test_taxonomy", "sister_id": "-- Select One --", "pick_table": "-- Select One --", "required": "0", "required_help_boolean": "0", "pick_format_type": "multi", "pick_format_single": "dropdown", "pick_format_single_help": "0", "pick_format_multi": "list", "pick_format_multi_help": "0", "pick_display_format_multi": "default", "pick_display_format_separator": ", ", "pick_allow_add_new": "1", "pick_taggable": "0", "pick_show_icon": "1", "pick_show_edit_link": "1", "pick_show_view_link": "1", "pick_limit": "0", "pick_user_role": "Administrator", "pick_post_status": "publish", "pick_post_author": "0", "repeatable": "0", "repeatable_format": "default", "roles_allowed": "administrator", "rest_pick_response": "array", "rest_pick_depth": "1" }, { "name": "rel_test_taxonomy", "id": 12, "label": "Rel Test Taxonomy", "description": "", "weight": 1, "type": "pick", "pick_object": "taxonomy", "sister_id": "-- Select One --", "pick_table": "-- Select One --", "required": "0", "required_help_boolean": "0", "pick_format_type": "multi", "pick_format_single": "dropdown", "pick_format_single_help": "0", "pick_format_multi": "list", "pick_format_multi_help": "0", "pick_display_format_multi": "default", "pick_display_format_separator": ", ", "pick_allow_add_new": "1", "pick_taggable": "0", "pick_show_icon": "1", "pick_show_edit_link": "1", "pick_show_view_link": "1", "pick_limit": "0", "pick_user_role": "Administrator", "pick_post_status": "publish", "pick_post_author": "0", "repeatable": "0", "repeatable_format": "default", "roles_allowed": "administrator", "rest_pick_response": "array", "rest_pick_depth": "1", "pick_val": "test_taxonomy" } ] } ] } ] }