logo
Ask your WordPress questions! Pay money and get answers fast! (more info)

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.

$15
User Profile Custom Meta - Display as drop down

Hello,

I am creating custom user meta fields which display on my profile page.

I have successfully configured them like so through my functions PHP.

function my_user_contactmethods($user_contactmethods) {

// You can get rid of ones you don't want

unset($user_contactmethods['jabber']);
unset($user_contactmethods['yim']);
unset($user_contactmethods['aim']);

// And add any news ones. The array key is the meta key name, the text
// is however you want it labelled.

$user_contactmethods['Title'] = __('Title');

$user_contactmethods['Publication / Company'] = __('Publication / Company');
$user_contactmethods['Job Title'] = __('Job Title');
$user_contactmethods['Publication Location'] = __('Publication Location');

$user_contactmethods['icl_admin_language'] = __('Language');

// etc for each field you want to appear
return $user_contactmethods;
}
add_filter( 'user_contactmethods', 'my_user_contactmethods');


But my problem is...

These user meta fields below are displaying as standard text inputs.


$user_contactmethods['Title'] = __('Title');

$user_contactmethods['icl_admin_language'] = __('Language');


I need the above to display as drop downs, instead of input boxs.

The drop down needs to have a label and value.

For example, for my meta_key: icl_admin_language

<select>
<option value="en">English</option>
<option value="es">Español</option>
<option value="it">Italiano</option>
</select>


How do I apply this to my function?

Thanks
Josh

------------------------------------------------

I had a guess, but no worky...


$user_contactmethods['icl_admin_language'] = __('Language'), true);
?><tr>
<td>
<select name="icl_admin_language" id="icl_admin_language" >
<option id="en"<?php selected( $user_contactmethods->icl_admin_language, 'en' ); ?>>English</option>
<option id="es"<?php selected( $user_contactmethods->icl_admin_language, 'es' ); ?>>Español</option>
<option id="it"<?php selected( $user_contactmethods->icl_admin_language, 'it' ); ?>>Italiano</option>
</select>
</td>
</tr><?php
}


This question has been answered.

Josh Cranwell | 01/28/12 at 6:24pm Edit

Previous versions of this question: 01/28/12 at 6:30pm | 01/28/12 at 6:30pm | 01/28/12 at 6:32pm | 01/28/12 at 6:49pm | 01/28/12 at 7:30pm

(1) Possible Answers Submitted...

See a chronological view of answers?

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

  • avatar
    Last edited:
    01/28/12
    7:34pm
    Ivaylo Draganov says:

    Hello,

    You are adding them to the contact methods array and it spawns only text fields. You should add them with the general action hooks. Using your example meta fields here's a sample code(duplicate the necessary chunks for other fields):
    http://pastebin.com/0zhWAtqY

    In future versions of WP this is going to be easier, but until then we're stuck to such code :--)

    • 01/28/12 7:40pm

      Josh Cranwell says:

      Thanks Ivaylo

      Lets I want to redo my...

      $user_contactmethods['Publication Location'] = __('Publication Location');

      ...in the same way so all my info is grouped together. Is it OK to have IDs with spaces?

      example...

      <select name="Publication Location" id="Publication Location">



    • 01/28/12 7:46pm

      Josh Cranwell says:

      Also I get a server error I use the code, does it work for you?

    • 01/28/12 7:50pm

      Ivaylo Draganov says:

      ...in the same way so all my info is grouped together. Is it OK to have IDs with spaces?


      I'm not sure if space are allowed in IDs or in meta field names. It's better to not use spaces. Check how exactly are your current meta fields stored - if they contain spaces you can change them.

      I made some edits to the code - there were some errors. I've tested it and it saves properly.

    • 01/28/12 8:15pm

      Josh Cranwell says:

      Thank you this worked...

      If I add some extra funds can you help me with this...

      I'm using the WP Front End plugin which pulls in the profile page onto the front end of my site.

      I add this code...

      <tr>

      <th><label for="icl_admin_language"><?php _e( 'Language' ); ?></label></th>
      <td>
      <?php $value = get_the_author_meta( 'icl_admin_language', $user->ID ); ?>
      <select name="icl_admin_language" id="icl_admin_language">
      <option value="en" <?php selected( $value, 'en' ); ?>>English</option>
      <option value="es" <?php selected( $value, 'es' ); ?>>Espanol</option>
      <option value="it" <?php selected( $value, 'it' ); ?>>Italiano</option>
      </select>
      </td>

      </tr>


      on line 160 in wpuf-editprofile.php

      I've attached the plugin (my version) here http://wtrns.fr/IU8ZCHJb1SFujda


      The select field now appears on my front end...

      but when I submit, it does not register the changes. I'm not sure where to put the code so when the form submits, it registers this field.

      If you can figure it out, can you tell me where to add the code so I can do it for my other custom meta fields.

      Thanks

    • 01/28/12 8:33pm

      Josh Cranwell says:

      To add the profile edit form to a post...

      Add this short code [wpuf_editprofile]

    • 01/28/12 9:18pm

      Josh Cranwell says:

      Figured it out, thanks for you help.

      Help me lots!

This question has expired.



Gabriel Reguly, idt, Hai Bui, Christianto, Josh Cranwell, Julio Potier, Francisco Javier Carazo Gil, Arnav Joy voted on this question.



Current status of this question: Completed



Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.