Title: user reference in relationship fields
Last modified: December 13, 2022

---

# user reference in relationship fields

 *  Resolved [markburton52](https://wordpress.org/support/users/markburton52/)
 * (@markburton52)
 * [3 years, 6 months ago](https://wordpress.org/support/topic/user-reference-in-relationship-fields/)
 * I’m trying to get WP user data to populate custom field types.
    I have the aditional
   field ids in extended user profiles (for a custom user role: artist) and can 
   access them in a pod and pod template so they appear in a page using that template.
   I’ve tried to create a relational field type so there would be a drop down of
   an administrator to select the relevant field value from the multiple user profiles.
   E.g. I have a field show name, and each user (artist in this case) has a specific
   value – I want to pull that value into the pod-defined custom post type “artist”.
   I can’t get it to work. I get the user display name, not the value of the field
   I’ve specified displaying. If I enable “more fields” in the artist page, then
   I have drop-downs available – they are the user display names and I want to pull
   the user profile field data in. What am I doing wrong?

Viewing 15 replies - 1 through 15 (of 24 total)

1 [2](https://wordpress.org/support/topic/user-reference-in-relationship-fields/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/user-reference-in-relationship-fields/page/2/?output_format=md)

 *  Plugin Support [pdclark](https://wordpress.org/support/users/pdclark/)
 * (@pdclark)
 * [3 years, 6 months ago](https://wordpress.org/support/topic/user-reference-in-relationship-fields/#post-16286255)
 * Assuming I have a Custom Post Type named `artist`, and in this CPT have defined
   a relationship field related to Users titled `artist_name`. Also assuming I only
   want to display one custom field in the dropdown menu, and that field is extended
   on Users with a name `pseudonym`:
 * In that case, it is possible to display that custom field in the drop down menu
   by selecting `Relationship Options` on the relationship field, then inputting`{
   @pseudonym}` into the field `Display Field in Selection List`.
 * If more than one field is required, then the `pods_field_pick_data` filter can
   be used. See [https://wordpress.org/support/topic/related-post-extra-field-display/#post-16264978](https://wordpress.org/support/topic/related-post-extra-field-display/#post-16264978)
   for an example of using this filter with a Posts relationship; it would need 
   slight modification to work with a User relationship.
 *  Thread Starter [markburton52](https://wordpress.org/support/users/markburton52/)
 * (@markburton52)
 * [3 years, 6 months ago](https://wordpress.org/support/topic/user-reference-in-relationship-fields/#post-16286674)
 * Thanks for the quick response.
    I’ve tried that and get this:
 * > Database Error; SQL: SELECT DISTINCT `t`.`ID`, `t`.`display_name`, `display_name`.`
   > meta_value` AS `display_name` FROM `wp_users` AS `t` LEFT JOIN `wp_usermeta`
   > AS `wp_capabilities` ON `wp_capabilities`.`meta_key` = ‘wp_capabilities’ AND`
   > wp_capabilities`.`user_id` = `t`.`ID` WHERE ( `wp_capabilities`.`meta_value`
   > LIKE “%\”artist\”%” ) ORDER BY `t`.`display_name`, `t`.`ID`; Response: Unknown
   > column ‘display_name.meta_value’ in ‘field list’
 * I’m not sure I’ve done the extend the field on users correctly. I have an extended
   post type “users”, and it has the relevant field (equivalent to your example “
   pseudonym”. It is a field we originally set up in Events Manager (under the booking
   system) but it does exist in the additional user type “artists”.
 *  Plugin Support [pdclark](https://wordpress.org/support/users/pdclark/)
 * (@pdclark)
 * [3 years, 6 months ago](https://wordpress.org/support/topic/user-reference-in-relationship-fields/#post-16286701)
 * Is the name of your custom field `display_name`? This is already a WordPress 
   core field name, which would cause confusion. The solution would be to rename
   the field.
 *  Thread Starter [markburton52](https://wordpress.org/support/users/markburton52/)
 * (@markburton52)
 * [3 years, 6 months ago](https://wordpress.org/support/topic/user-reference-in-relationship-fields/#post-16286742)
 * No it’s dbem_caf_show_name Could it be that it is used in the user profile and
   in the Event Manager booking system and in an Ultimate Member form – however 
   these plug-ins and the WP profile don’t appear to conflict – updating the field
   in one updates it in the other places as we expected.
 *  Plugin Support [pdclark](https://wordpress.org/support/users/pdclark/)
 * (@pdclark)
 * [3 years, 6 months ago](https://wordpress.org/support/topic/user-reference-in-relationship-fields/#post-16286753)
 * If you’ve entered `{@dbem_caf_show_name}` into the field, I would expect it to
   work. You could try temporarily disabling those plugins to rule out conflicts,
   or try the PHP filter.
 *  Thread Starter [markburton52](https://wordpress.org/support/users/markburton52/)
 * (@markburton52)
 * [3 years, 6 months ago](https://wordpress.org/support/topic/user-reference-in-relationship-fields/#post-16288352)
 * OK, thanks. I tried disabling the plugins and the error is still there.
    So I’ll
   have a go with the filter. Do I simply replace the text in these lines with the
   relevant fields?
 * > $relationship_field_name = ‘PUT_NAME_OF_THE_RELATIONSHIP_FIELD_HERE’;
   >  $post_type
   > = ‘PUT_NAME_OF_THE_POST_TYPE_EXTENDED_BY_PODS_HERE’;
 * You mentioned that
 * >  it would need slight modification to work with a User relationship.
 *  – how do I do that? It looks like “[https://developer.wordpress.org/reference/functions/get_user_meta/&#8221](https://developer.wordpress.org/reference/functions/get_user_meta/&#8221);
   needs to be used somewhere. COuld you give me some guidance on how and where 
   to use it? Or if it’s not that, then what? I only want to display one relationship
   field in the drop-down (though there will be several such fields making use of
   the same relationship in the autotemplate.
    Thank you.
 *  Thread Starter [markburton52](https://wordpress.org/support/users/markburton52/)
 * (@markburton52)
 * [3 years, 6 months ago](https://wordpress.org/support/topic/user-reference-in-relationship-fields/#post-16293456)
 * Further to this, I’ve not tried using the code snippet as I don’t know how to
   customise it.
    I’ve stripped down what I’m asking the pod and template to do 
   and a lot of the error message has gone, but this part is still there.
 * > Database Error; SQL: SELECT DISTINCT `t`.`ID`, `t`.`display_name`, `display_name`.`
   > meta_value` AS `display_name` FROM `wp_users` AS `t` ORDER BY `t`.`display_name`,`
   > t`.`ID`; Response: Unknown column ‘display_name.meta_value’ in ‘field list’
 * It’s curious because I’m not asking for the display name. Do I need to somehow
   reference it?
    Thanks
 *  Plugin Support [pdclark](https://wordpress.org/support/users/pdclark/)
 * (@pdclark)
 * [3 years, 6 months ago](https://wordpress.org/support/topic/user-reference-in-relationship-fields/#post-16294981)
 * Curious indeed. Here is a modified code snippet that should work, with the following
   assumptions:
 * Relationship Field Name: `artist_user`
   Post Type: `artist`User Field Name: `dbem_caf_show_name`
 *     ```wp-block-code
       <?php
   
       add_filter(
       	'pods_field_pick_data',
       	function( $data, $name, $value, $options, $pod, $id ){
   
       		$relationship_field_name = 'artist_user';
       		$post_type = 'artist';
   
       		if ( false !== strpos( $name, $relationship_field_name ) ) {
       			foreach( $data as $id => & $label ) {
       				$label = get_user_meta( $id, 'dbem_caf_show_name', true );
       			}
       		}
       		return $data;
       	},
       	10,
       	6
       );
       ```
   
 *  Thread Starter [markburton52](https://wordpress.org/support/users/markburton52/)
 * (@markburton52)
 * [3 years, 6 months ago](https://wordpress.org/support/topic/user-reference-in-relationship-fields/#post-16295939)
 * Thank you for doing this. I added the snippet (changing the ‘artist_user’ field
   to the one i’m using (dbem_caf_bring_show-name’, and activated it but I still
   get the same error:
 * > Database Error; SQL: SELECT DISTINCT `t`.`ID`, `t`.`display_name`, `display_name`.`
   > meta_value` AS `display_name` FROM `wp_users` AS `t` ORDER BY `t`.`display_name`,`
   > t`.`ID`; Response: Unknown column ‘display_name.meta_value’ in ‘field list’
   > I can’t see ‘display_name’ cited anywhere, in the pod, the pod template, or
   > the snippet, so I’m mystified as to why it is popping up here.
 *  Thread Starter [markburton52](https://wordpress.org/support/users/markburton52/)
 * (@markburton52)
 * [3 years, 6 months ago](https://wordpress.org/support/topic/user-reference-in-relationship-fields/#post-16295954)
 * Perhaps I need to alter a setting in the advanced settings for the pod? I can
   see settings for filter and hooks…?
 *  Plugin Author [Jory Hogeveen](https://wordpress.org/support/users/keraweb/)
 * (@keraweb)
 * [3 years, 5 months ago](https://wordpress.org/support/topic/user-reference-in-relationship-fields/#post-16302505)
 * Hi [@markburton52](https://wordpress.org/support/users/markburton52/)
 * Could you check where this query is made from? I think this error might be unrelated
   to the code Paul posted.
 * Do you still have a value set within the field settings for example? Please remove
   that since you are switching to PHP 🙂
 * Cheers, Jory
 *  Thread Starter [markburton52](https://wordpress.org/support/users/markburton52/)
 * (@markburton52)
 * [3 years, 5 months ago](https://wordpress.org/support/topic/user-reference-in-relationship-fields/#post-16302560)
 * Thanks but I’m not sure what you mean.
   a) Where the query is made from. Do you
   mean in the setting of the fields in edit pods vs in the php snippet?
 * b) Assuming the above, then what should go in the field setting in pods edit?
 *  Plugin Support [pdclark](https://wordpress.org/support/users/pdclark/)
 * (@pdclark)
 * [3 years, 5 months ago](https://wordpress.org/support/topic/user-reference-in-relationship-fields/#post-16302563)
 * The field setting should be blank.
 *  Thread Starter [markburton52](https://wordpress.org/support/users/markburton52/)
 * (@markburton52)
 * [3 years, 5 months ago](https://wordpress.org/support/topic/user-reference-in-relationship-fields/#post-16302838)
 * Great, that finally worked.
 * Thanks again for all your help.
 *  Thread Starter [markburton52](https://wordpress.org/support/users/markburton52/)
 * (@markburton52)
 * [3 years, 5 months ago](https://wordpress.org/support/topic/user-reference-in-relationship-fields/#post-16325317)
 * I’m re-opening this with a further question.
 * I now want to do the same thing for further pairs of codes. I tried to repeat
   the sequence for another code:
 *     ```wp-block-code
       add_filter(
       	'pods_field_pick_data',
       	function( $data, $name, $value, $options, $pod, $id ){
   
       		$relationship_field_name = 'dbem_caf_bring_show_name';
       		$post_type = 'artist';
   
       		if ( false !== strpos( $name, $relationship_field_name ) ) {
       			foreach( $data as $id => & $label ) {
       				$label = get_user_meta( $id, 'dbem_caf_show_name', true );
       			}
       		}
       		return $data;
       	},
       	10,
       	6
       );
       add_filter(
       	'pods_field_pick_data',
       	function( $data, $name, $value, $options, $pod, $id ){
   
       		$relationship_field_name = 'dbem_caf_bring_about_the_artist';
       		$post_type = 'artist';
   
       		if ( false !== strpos( $name, $relationship_field_name ) ) {
       			foreach( $data as $id => & $label ) {
       				$label = get_user_meta( $id, 'dbem_caf_about_the_artist', true );
       			}
       		}
       		return $data;
       	},
       	10,
       	6
       );
       ```
   
 * However, that throws an error when I insert this as a new snippet. I must have
   the syntax wrong – how should I do this, and do for multiploe code pairs? Thanks.

Viewing 15 replies - 1 through 15 (of 24 total)

1 [2](https://wordpress.org/support/topic/user-reference-in-relationship-fields/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/user-reference-in-relationship-fields/page/2/?output_format=md)

The topic ‘user reference in relationship fields’ is closed to new replies.

 * ![](https://ps.w.org/pods/assets/icon.svg?rev=3286397)
 * [Pods - Custom Content Types and Fields](https://wordpress.org/plugins/pods/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/pods/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/pods/)
 * [Active Topics](https://wordpress.org/support/plugin/pods/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/pods/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/pods/reviews/)

## Tags

 * [relationship fields](https://wordpress.org/support/topic-tag/relationship-fields/)

 * 24 replies
 * 3 participants
 * Last reply from: [pdclark](https://wordpress.org/support/users/pdclark/)
 * Last activity: [3 years, 5 months ago](https://wordpress.org/support/topic/user-reference-in-relationship-fields/page/2/#post-16342800)
 * Status: resolved