Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

{@user} taxonomy relationship magic tags output only first ID or pass false #7150

Open
pd-cm opened this issue Sep 1, 2023 · 1 comment · May be fixed by #7153
Open

{@user} taxonomy relationship magic tags output only first ID or pass false #7150

pd-cm opened this issue Sep 1, 2023 · 1 comment · May be fixed by #7153
Assignees
Labels
Milestone

Comments

@pd-cm
Copy link
Contributor

pd-cm commented Sep 1, 2023

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:

  • In a query for a CPT, {@user.field} outputs only the first term, and it's the Term ID.
  • In a query for a CPT, {@user.field,helper_function} passes false to the helper.
  • In a query over users, {@field} passes a formatted string of Term Names with "and".
  • In a query over users, {@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

  1. Import the pods.json
  2. Unzip and import this WXR: usertaxonomy.WordPress.2023-09-01.xml.zip
  3. Assign multiple taxonomy terms to the current user using both fields on the user profile page.
  4. Add this function:
function terms_from_taxonomy_relationship_magic_tag( $value ) {
	ob_start();
	var_dump( $value );
	return str_replace( PHP_EOL, '', ob_get_clean() );
}
  1. View the page titled "test".

Screenshots / Screencast

Term 2 is term_id 4. Term 3 is term_id 5.

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, and pod_item_id are all of type string, while integer would most likely be appropriate.

Screenshot 2023-09-01 at 1 23 40 PM Screenshot 2023-09-01 at 1 24 18 PM

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"
                        }
                    ]
                }
            ]
        }
    ]
}
@pd-cm pd-cm added the Type: Bug label Sep 1, 2023
@JoryHogeveen JoryHogeveen self-assigned this Sep 4, 2023
@JoryHogeveen JoryHogeveen added this to the Pods 3.0 milestone Sep 4, 2023
@JoryHogeveen JoryHogeveen moved this from 🆕 New to 🔖 Ready in Pods Core - Maintenance Sep 4, 2023
@JoryHogeveen JoryHogeveen linked a pull request Sep 4, 2023 that will close this issue
4 tasks
@JoryHogeveen
Copy link
Member

JoryHogeveen commented Sep 4, 2023

Hi @pd-cm
Could you please test my patch for this issue? #7153

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.

Users do not have taxonomies by default in WordPress, therefore these are not reserved keys for users.
When using relationship fields these taxonomies are not stored as term relationships but as metadata.

@JoryHogeveen JoryHogeveen added the Status: Has Patch Has a linked PR label Sep 4, 2023
@sc0ttkclark sc0ttkclark modified the milestones: Pods 3.0, Pods 3.2 Sep 12, 2023
@sc0ttkclark sc0ttkclark modified the milestones: Pods 3.2, Pods 3.3 Dec 11, 2023
@JoryHogeveen JoryHogeveen modified the milestones: Pods 3.3, Pods 3.2 Feb 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: 🔖 Ready
Development

Successfully merging a pull request may close this issue.

3 participants