- This topic has 3 replies, 2 voices, and was last updated 6 years, 7 months ago by
Steve.
-
AuthorPosts
-
-
June 17, 2015 at 5:19 pm #3892
justinMemberI created this select field inside of the user profiles. It works as expected in my user profile. When I go to edit someone else’s profile, it has a dropped down full of empty white selections. If you inspect the select button, all of the Id’s are populating in the values, but the display name does not show. If I switch it to user_login, it displays, but ideally I would like to use their display name.
$user_id = (int) $user_id; $current_user = wp_get_current_user(); if ( ! defined( 'IS_PROFILE_PAGE' ) ) define( 'IS_PROFILE_PAGE', ( $user_id == $current_user->ID ) ); if ( ! $user_id && IS_PROFILE_PAGE ) $user_id = $current_user->ID; elseif ( ! $user_id && ! IS_PROFILE_PAGE ) wp_die(__( 'Invalid user ID.' ) ); elseif ( ! get_userdata( $user_id ) ) wp_die( __('Invalid user ID.') ); $spouse_id = $user_id; piklist('field', array( 'type' => 'select' ,'field' => 'user_spouse' ,'label' => 'Your Spouse' ,'value' => '0' // Sets default to None ,'description' => 'Please select your spouse below' ,'choices' => array( 0 => "Not Married" ) + piklist( get_users( array( 'orderby' => 'display_name' ,'order' => 'asc' ,'exclude' => $spouse_id ,'fields' => array('ID', 'display_name') ) ,'objects' ) ,array( 'ID' ,'display_name' ) ) )); -
June 18, 2015 at 10:37 am #3894
SteveKeymaster@justin– This works for me… with two little changes that are throwing errors:
1)
$user_id = (int) $user_id;
This is throwing an error so I removed it: Notice: Undefined variable: user_id2)
define( 'IS_PROFILE_PAGE', ( $user_id == $current_user->ID ) );
This should be single =, not ==If I make those two changes it works for me with display_name.
-
June 18, 2015 at 10:45 am #3896
justinMemberYea it seems to work now.
Thank you very much Steve.
-
June 18, 2015 at 10:49 am #3897
SteveKeymasterGreat. Closing ticket.
-
-
AuthorPosts
- The topic ‘User query select field’ is closed to new replies.