Tagged: , ,

Viewing 3 reply threads
  • Author
    Posts
    • #3892
      justin
      Member

      I 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'
      						)
      						)
            )); 
    • #3894
      Steve
      Keymaster

      @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_id

      2) 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.

    • #3896
      justin
      Member

      Yea it seems to work now.

      Thank you very much Steve.

    • #3897
      Steve
      Keymaster

      Great. Closing ticket.

Viewing 3 reply threads
  • The topic ‘User query select field’ is closed to new replies.