pods-framework / pods

The Pods Framework is a Content Development Framework for WordPress - It lets you create and extend content types that can be used for any project. Add fields of various types we've built in, or add your own with custom inputs, you have total control.
https://pods.io/
GNU General Public License v2.0
1.07k stars 265 forks source link

Pods custom relationship field won't display custom user meta in selection list #5384

Open eden-i72 opened 5 years ago

eden-i72 commented 5 years ago

Issue Overview

My site has a Report pod with a Depositor custom relationship field. Depositor is related to Users. The Display Field in Selection List for the Depositor field is set to a custom user meta (custom field added by a different plugin) but the Depositor dropdown on the Add/Edit screen for the Report pod is showing the display name of each user instead.

EDITED 06/05 when I realized that I extended users after creating the relationship field (just switched the order of steps to reproduce)

Was able to reproduce this myself on a separate site using a field added to the author role by ACF Pro. WordPress environment and Pods package export below are still from the site where I saw the issue originally but I can provide that for the second site if needed.

Expected Behavior

The reports pod Depositor field should show the depositor code of each user in the dropdown.

Current Behavior

On the Add/Edit report screen (for the Report pod), the pod Depositor field shows the display name of each user even though it is set to display the custom field added to users.

I know that Pods can see the custom field because it displays it in a shortcode ([pods name="user" id="2" field="wpc_cf_depositor_code"])

Add New Report screen with depositor dropdown open. Actual options are hidden in Photoshop but text over them says 'These are all names' Depositor custom field on Pods edit screen showing Basic tab Depositor custom field on Pods edit screen showing Additional Field Options tab

Steps to Reproduce (for bugs)

  1. Add a custom user role with anything other than Pods (we're using WPC Client role created by the WP Client plugin, but that's a paid plugin and may not be necessary to reproduce this)
  2. Add a custom Depositor Code text field to that user role using something other than Pods (Again we did this with WP Client--more specific instructions for that plugin further down). The meta key for this field is wpc_cf_depositor_code.
    • If you can't get a copy of WP Client for testing, just make sure your custom meta shows up in the wp_usermeta table when you set that field for users
  3. Add a few new users with the custom role you created and set their Depositor Code field. Search for your custom meta_key in wp_usermeta to confirm it's working correctly
  4. Create a Report pod with the following options:
    1. Labels tab:
      • Label: Reports
      • Singular Label: Report
    2. Admin UI tab:
      • Text fields (Post Type Description, Parent Menu ID, Menu Name, Menu Position, Menu Icon, Admin bar name) should all be blank
      • Show Admin UI, Show Admin Menu in Dashboard, Show in Navigation Menus and Show in Admin Bar "New" Menu should be checked
    3. Advanced Options tab (anything not mentioned is blank)
      • Public: Checked
      • Publicly Queryable: Checked
      • Exclude from Search: Unchecked
      • User Capability: post
      • Additional User Capabilities: Checked
      • Enable Archive Page: Unchecked
      • Rewrite: Checked
      • Rewrite with Front: Checked
      • Rewrite Pages: Checked
      • Query Var: Checked
      • Exportable: Checked
      • Default Status: Published
      • Supports: Title
      • Built-in Taxonomies: Nothing checked
    4. Auto Template Options: Enable Automatic Pods Templates for this Pod is unchecked
    5. REST API tab: Enable is unchecked
  5. In the manage Fields tab of the report pod you just created, add a relationship field with the following options:
    1. In the basic tab:
      • Label: Depositor
      • Name: subscriber_code
      • Field Type: Relationship
      • Related To: Users
    2. In the additional Field Options tab:
      • Selection Type: Single Select *Format: Drop Down
      • Allow Add New: Yes
      • Display Field in Selection List: {@wpc_cf_depositor_code} (or other valid meta_key in the wp_usermeta table that was created/set outside of Pods)
      • Limit List to Role(s): WPC Client, WPC Client STAFF (or other custom user roles created outside of Pods)
    3. Advanced tab: everything blank (no checkboxes checked)
    4. REST API tab: Checkboxes unchecked, other fields have what appears to be a default value
      • Response Type: Full
      • Depth: 2
  6. Add a new Pod that extends Users, and save it without making any additional changes
  7. Add a new page, putting the shortcode [pods name="user" id="[whatever your user ID is]" field="wpc_cf_depositor_code"] in the content. Publish it or save it as a draft, and view it.
    • Notice the depositor code for that user is showing correctly
  8. Click the Reports pod in the admin menu and add a new report
  9. Notice that the Depositor dropdown is showing the display name of each user and not their depositor code

WP-Client-Specific Steps to Create a Custom Field

This is a paid plugin and I don't know if they have any sort of demo version that will allow you to do this for free. In case you are able to, here's how the custom field is set up:

In the WP Client plugin, go to Members > Custom Fields and click Add New Custom Field. In the Add Custom Field form:

  1. Field Slug: wpc_cf_depositor_code
  2. Field Type: Text Box
  3. Field Title: Depositor Code
  4. Required Field: Unchecked
  5. Relate to User Meta: Leave blank
  6. Field For: Clients
  7. Field Mask: Without Mask
  8. Field View: Everything for Administrators, WPC Admins , and WPC Managers should be set to edit. Everything for WPC Clients should be set to Hide

Possible Solution

WordPress Environment

WordPress Version: 5.1.1 PHP Version: 5.6.40 MySQL Version: 5.6.44 Server Software: Apache Your User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Firefox/68.0 Session Save Path: /var/cpanel/php/sessions/ea-php56 Session Save Path Exists: Yes Session Save Path Writeable: Yes Session Max Lifetime: 1440 Opcode Cache: Apc: No Memcached: No OPcache: No Redis: No Object Cache: APC: No APCu: No Memcache: No Memcached: No Redis: No WPDB Prefix: wp_ WP Multisite Mode: No WP Memory Limit: 40M Current Memory Usage: 54.441M Current Memory Usage (real): 55.000M Pods Network-Wide Activated: No Pods Install Location: /home/nesad/public_html/wp-content/plugins/pods/ Pods Tableless Mode Activated: No Pods Light Mode Activated: No Currently Active Theme: NESAD Currently Active Plugins: Advanced Custom Fields: 5.7.12 All In One SEO Pack: 2.12 Classic Editor: 1.4 CSV Importer For Pods: 0.8 FeedWordPress: 2017.1020 Feedwordpress Advanced Filters: 0.6.2 Pods - Custom Content Types and Fields: 2.7.12 TinyMCE Advanced: 5.1.0 Visual Form Builder: 2.9.9 WP-Client: 4.4.7.4 WP-Client: Advanced Member Site: 1.5.3 WP-Client: Private Post Types: 1.5.2

Pods Package Export (helpful!)

{"meta":{"version":"2.7.12","build":1559661457},"pods":{"649":{"id":649,"name":"faq","label":"FAQs","description":"","type":"post_type","storage":"meta","object":"","alias":"","fields":[],"show_in_menu":1,"label_singular":"FAQ","public":"1","show_ui":"1","supports_title":"1","supports_editor":"1"},"653":{"id":653,"name":"plan","label":"Plans","description":"","type":"post_type","storage":"meta","object":"","alias":"","fields":{"include_dollar_sign":{"id":7641,"name":"include_dollar_sign","label":"Include Dollar Sign","description":"Select yes to include the currency symbol.","help":"","class":"","type":"boolean","weight":0,"pick_object":"","pick_val":"","sister_id":"","required":"0","pick_allow_html":"0","boolean_format_type":"checkbox","boolean_yes_label":"Yes","boolean_no_label":"No","admin_only":"0","restrict_role":"0","restrict_capability":"0","hidden":"0","read_only":"0","roles_allowed":["administrator"],"unique":"0"},"cost":{"id":7642,"name":"cost","label":"Cost","description":"Large Text","help":"","class":"","type":"text","weight":1,"pick_object":"","pick_val":"","sister_id":"","required":"0","text_allow_shortcode":"0","text_allow_html":"0","text_allowed_html_tags":"strong em a ul ol li b i","text_max_length":"255","pick_allow_html":"0","admin_only":"0","restrict_role":"0","restrict_capability":"0","hidden":"0","read_only":"0","roles_allowed":["administrator"],"unique":"0","text_repeatable":"0","text_placeholder":""},"cost_interval":{"id":655,"name":"cost_interval","label":"Cost Interval","description":"","help":"","class":"","type":"text","weight":2,"pick_object":"","pick_val":"","sister_id":"","required":"0","text_allow_shortcode":"0","text_allow_html":"0","text_allowed_html_tags":"strong em a ul ol li b i","text_max_length":"255","pick_allow_html":"0","admin_only":"0","restrict_role":"0","restrict_capability":"0","hidden":"0","read_only":"0","roles_allowed":["administrator"],"unique":"0","text_repeatable":"0","text_placeholder":""},"plan_detail_excerpt":{"id":656,"name":"plan_detail_excerpt","label":"Plan Detail Excerpt","description":"","help":"","class":"","type":"wysiwyg","weight":3,"pick_object":"","pick_val":"","sister_id":"","required":"0","wysiwyg_editor":"tinymce","wysiwyg_media_buttons":"1","wysiwyg_oembed":"0","wysiwyg_wptexturize":"1","wysiwyg_convert_chars":"1","wysiwyg_wpautop":"1","wysiwyg_allow_shortcode":"0","pick_allow_html":"0","admin_only":"0","restrict_role":"0","restrict_capability":"0","hidden":"0","read_only":"0","roles_allowed":["administrator"],"unique":"0","wysiwyg_repeatable":"0","wysiwyg_allowed_html_tags":""},"plan_detail":{"id":657,"name":"plan_detail","label":"Plan Detail","description":"This content appears only on the Subscribe page, below the boxes.","help":"","class":"","type":"wysiwyg","weight":4,"pick_object":"","pick_val":"","sister_id":"","required":"0","wysiwyg_editor":"tinymce","wysiwyg_media_buttons":"1","wysiwyg_oembed":"0","wysiwyg_wptexturize":"1","wysiwyg_convert_chars":"1","wysiwyg_wpautop":"1","wysiwyg_allow_shortcode":"0","pick_allow_html":"0","admin_only":"0","restrict_role":"0","restrict_capability":"0","hidden":"0","read_only":"0","roles_allowed":["administrator"],"unique":"0","wysiwyg_repeatable":"0","wysiwyg_allowed_html_tags":""},"level_id":{"id":1865,"name":"level_id","label":"Corresponding Level ID","description":"The ID of the payment level from WP Client Portal - Advanced Member Site subscriptions. Example: 1460041781","help":"","class":"","type":"text","weight":5,"pick_object":"","pick_val":"","sister_id":"","required":"0","text_allow_shortcode":"0","text_allow_html":"0","text_allowed_html_tags":"strong em a ul ol li b i","text_max_length":"255","pick_allow_html":"0","admin_only":"0","restrict_role":"0","restrict_capability":"0","hidden":"0","read_only":"0","roles_allowed":["administrator"],"unique":"0","text_repeatable":"0","text_placeholder":""}},"show_in_menu":"1","label_singular":"Plan","public":"1","show_ui":"1","supports_title":"1","supports_editor":"1","publicly_queryable":"1","exclude_from_search":"0","capability_type":"post","capability_type_custom":"plan","capability_type_extra":"1","has_archive":"0","hierarchical":"0","rewrite":"1","rewrite_with_front":"1","rewrite_feeds":"0","rewrite_pages":"1","query_var":"1","can_export":"1","default_status":"draft","supports_author":"0","supports_thumbnail":"0","supports_excerpt":"0","supports_trackbacks":"0","supports_custom_fields":"0","supports_comments":"0","supports_revisions":"0","supports_page_attributes":"0","supports_post_formats":"0","built_in_taxonomies_category":"0","built_in_taxonomies_link_category":"0","built_in_taxonomies_post_tag":"0","built_in_taxonomies_wpc_file_tags":"0","built_in_taxonomies_wpc_tags":"0","menu_position":"0","show_in_nav_menus":"1","show_in_admin_bar":"1","pfat_enable":"0","pfat_append_single":"append","pfat_append_archive":"append","pfat_filter_single":"the_content","pfat_filter_archive":"the_content"},"290":{"id":290,"name":"report","label":"Reports","description":"","type":"post_type","storage":"table","object":"","alias":"","fields":{"report_type":{"id":412,"name":"report_type","label":"Report Type","description":"","help":"","class":"","type":"text","weight":0,"pick_object":"","pick_val":"","sister_id":"","required":"0","unique":"0","text_allow_shortcode":"0","text_allow_html":"0","text_allowed_html_tags":"strong em a ul ol li b i","text_max_length":"255","pick_allow_html":"0","admin_only":"0","restrict_role":"0","restrict_capability":"0","hidden":"0","read_only":"0","roles_allowed":["administrator"],"text_repeatable":"0","text_placeholder":""},"report_subtype":{"id":396,"name":"report_subtype","label":"Report Subtype","description":"","help":"","class":"","type":"text","weight":1,"pick_object":"","pick_val":"","sister_id":"","required":"0","unique":"0","text_allow_shortcode":"0","text_allow_html":"0","text_allowed_html_tags":"strong em a ul ol li b i","text_max_length":"255","pick_allow_html":"0","admin_only":"0","restrict_role":"0","restrict_capability":"0","hidden":"0","read_only":"0","roles_allowed":["administrator"],"text_repeatable":"0","text_placeholder":""},"subscriber_code":{"id":291,"name":"subscriber_code","label":"Depositor","description":"","help":"","class":"","type":"pick","weight":2,"pick_object":"user","pick_val":"","sister_id":"","required":"0","unique":"0","pick_format_type":"single","pick_format_single":"dropdown","pick_format_multi":"checkbox","pick_taggable":"0","pick_limit":"0","pick_allow_html":"0","pick_user_role":["wpc_client"],"admin_only":"0","restrict_role":"0","restrict_capability":"0","hidden":"0","read_only":"0","roles_allowed":["administrator"],"pick_table":"wp_usermeta","pick_display":"{@wpc_cf_depositor_code}","pick_allow_add_new":"1","pick_show_icon":"1","pick_show_edit_link":"1","pick_show_view_link":"1","pick_post_status":[],"rest_read":"0","rest_write":"0","rest_pick_response":"array","rest_pick_depth":"2","pick_select_text":"","pick_table_id":"","pick_table_index":"","pick_where":"","pick_orderby":"","pick_groupby":""},"report_date":{"id":334,"name":"report_date","label":"Report Date","description":"","help":"","class":"","type":"date","weight":3,"pick_object":"","pick_val":"","sister_id":"","required":"0","unique":"0","date_format":"mdy","date_allow_empty":"1","date_html5":"0","pick_allow_html":"0","admin_only":"0","restrict_role":"0","restrict_capability":"0","hidden":"0","read_only":"0","roles_allowed":["administrator"],"date_repeatable":"0","date_type":"format","date_format_custom":"","date_format_custom_js":""},"file_code":{"id":337,"name":"file_code","label":"File Code","description":"","help":"","class":"","type":"text","weight":4,"pick_object":"","pick_val":"","sister_id":"","required":"0","unique":"0","text_allow_shortcode":"0","text_allow_html":"0","text_allowed_html_tags":"strong em a ul ol li b i","text_max_length":"255","pick_allow_html":"0","admin_only":"0","restrict_role":"0","restrict_capability":"0","hidden":"0","read_only":"0","roles_allowed":["administrator"],"text_repeatable":"0","text_placeholder":""},"location_name":{"id":338,"name":"location_name","label":"Location Name","description":"","help":"","class":"","type":"text","weight":5,"pick_object":"","pick_val":"","sister_id":"","required":"0","unique":"0","text_allow_shortcode":"0","text_allow_html":"0","text_allowed_html_tags":"strong em a ul ol li b i","text_max_length":"255","pick_allow_html":"0","admin_only":"0","restrict_role":"0","restrict_capability":"0","hidden":"0","read_only":"0","roles_allowed":["administrator"],"text_repeatable":"0","text_placeholder":""},"location_address":{"id":339,"name":"location_address","label":"Location Address","description":"","help":"","class":"","type":"text","weight":6,"pick_object":"","pick_val":"","sister_id":"","required":"0","unique":"0","text_allow_shortcode":"0","text_allow_html":"0","text_allowed_html_tags":"strong em a ul ol li b i","text_max_length":"255","pick_allow_html":"0","admin_only":"0","restrict_role":"0","restrict_capability":"0","hidden":"0","read_only":"0","roles_allowed":["administrator"],"text_repeatable":"0","text_placeholder":""},"city":{"id":340,"name":"city","label":"City","description":"","help":"","class":"","type":"text","weight":7,"pick_object":"","pick_val":"","sister_id":"","required":"0","unique":"0","text_allow_shortcode":"0","text_allow_html":"0","text_allowed_html_tags":"strong em a ul ol li b i","text_max_length":"255","pick_allow_html":"0","admin_only":"0","restrict_role":"0","restrict_capability":"0","hidden":"0","read_only":"0","roles_allowed":["administrator"],"text_repeatable":"0","text_placeholder":""},"state":{"id":341,"name":"state","label":"State","description":"","help":"","class":"","type":"text","weight":8,"pick_object":"","pick_val":"","sister_id":"","required":"0","unique":"0","text_allow_shortcode":"0","text_allow_html":"0","text_allowed_html_tags":"strong em a ul ol li b i","text_max_length":"255","pick_allow_html":"0","admin_only":"0","restrict_role":"0","restrict_capability":"0","hidden":"0","read_only":"0","roles_allowed":["administrator"],"text_repeatable":"0","text_placeholder":""},"zip":{"id":342,"name":"zip","label":"Zip","description":"","help":"","class":"","type":"text","weight":9,"pick_object":"","pick_val":"","sister_id":"","required":"0","unique":"0","text_allow_shortcode":"0","text_allow_html":"0","text_allowed_html_tags":"strong em a ul ol li b i","text_max_length":"255","pick_allow_html":"0","admin_only":"0","restrict_role":"0","restrict_capability":"0","hidden":"0","read_only":"0","roles_allowed":["administrator"],"text_repeatable":"0","text_placeholder":""},"latitude":{"id":343,"name":"latitude","label":"Latitude","description":"","help":"","class":"","type":"text","weight":10,"pick_object":"","pick_val":"","sister_id":"","required":"0","unique":"0","text_allow_shortcode":"0","text_allow_html":"0","text_allowed_html_tags":"strong em a ul ol li b i","text_max_length":"255","pick_allow_html":"0","admin_only":"0","restrict_role":"0","restrict_capability":"0","hidden":"0","read_only":"0","roles_allowed":["administrator"],"text_repeatable":"0","text_placeholder":""},"longitude":{"id":344,"name":"longitude","label":"Longitude","description":"","help":"","class":"","type":"text","weight":11,"pick_object":"","pick_val":"","sister_id":"","required":"0","unique":"0","text_allow_shortcode":"0","text_allow_html":"0","text_allowed_html_tags":"strong em a ul ol li b i","text_max_length":"255","pick_allow_html":"0","admin_only":"0","restrict_role":"0","restrict_capability":"0","hidden":"0","read_only":"0","roles_allowed":["administrator"],"text_repeatable":"0","text_placeholder":""}},"show_in_menu":"1","label_singular":"Report","public":"1","show_ui":"1","supports_title":"1","supports_editor":"0","publicly_queryable":"1","exclude_from_search":"0","capability_type":"post","capability_type_custom":"report","capability_type_extra":"1","has_archive":"0","hierarchical":"0","rewrite":"1","rewrite_with_front":"1","rewrite_feeds":"0","rewrite_pages":"1","query_var":"1","can_export":"1","default_status":"publish","supports_author":"0","supports_thumbnail":"0","supports_excerpt":"0","supports_trackbacks":"0","supports_custom_fields":"0","supports_comments":"0","supports_revisions":"0","supports_page_attributes":"0","supports_post_formats":"0","built_in_taxonomies_category":"0","built_in_taxonomies_link_category":"0","built_in_taxonomies_post_tag":"0","built_in_taxonomies_wpc_file_tags":"0","built_in_taxonomies_wpc_tags":"0","show_in_nav_menus":"1","show_in_admin_bar":"1","pfat_enable":"0","pfat_append_single":"append","pfat_append_archive":"append","pfat_filter_single":"the_content","pfat_filter_archive":"the_content","pfat_run_outside_loop":"0","rest_enable":"0","read_all":"0","write_all":"0"},"127988":{"id":127988,"name":"user","label":"User","description":"","type":"user","storage":"meta","object":"user","alias":"","fields":[],"show_in_menu":1,"rest_enable":"0","read_all":"0","write_all":"0"}}}

Workaround or Alternate Solution Until Bug is Addressed

Related Issues and/or PRs

issue-label-bot[bot] commented 5 years ago

Issue-Label Bot is automatically applying the label Type: Bug to this issue, with a confidence of 0.92. Please mark this comment with :thumbsup: or :thumbsdown: to give our bot feedback!

Links: app homepage, dashboard and code for this bot.

JoryHogeveen commented 5 years ago

Hello @eden-i72,

I've tried to reproduce your issue but it all works fine here. I can switch to any meta_key I want and that field data shows in the dropdown. Also when filtering on user role it keeps working fine.

Do you happen to have a dev environment that I can take a look at?