WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a multisite setup and I am adding some additional information fields in the profile edit screen in my theme's dashboard. I am primarily using text fields however I have a drop down selection menu for the author's country

<select name="country" class="mid2" id="country"  value="<?php echo $userdata->country ?>" style="width:150px;">

My problem is that if a user selects "Togo" for example it registers the change (I know this because it echoes it in the author's bio page) but the default value in the drop down menu (In this case the United States) always stays the same.

Any ideas on how I can have it display whichever country the author has selected?

share|improve this question
Let me guess: You hacked the core? – kaiser Sep 14 '11 at 21:54
Nope, no hacking involved (I like to keep my WP installs intact ;]). I'm actually running this through the template using a variation of this code wordpress.org/support/topic/… – Dean Elliott Sep 14 '11 at 21:59
up vote 2 down vote accepted

Wordpress has a great little function built in for handling selections.

<option <?php selected('value1', 'value2');?> value='foo'>Bar</option>

You can also check out these form handling functions:

Your HTML syntax is wrong as well. Per W3C, 'value' is not an attribute of the select tag. The value of a select is defined in the options of a select. It should look like this:

<select name="country" class="mid2" id="country" style="width:150px;">
    <option value="US" <?php selected('US', $userdata->country);?>>USA</option>
    <option value="ES" <?php selected('ES', $userdata->country);?>>Spain</option>
    <option value="FR" <?php selected('FR', $userdata->country);?>>France</option>
share|improve this answer

So you say it registers the change, so it doesn't really sound like its a Wordpress problem but here is how you would display that anyways.

<option value="your_value" <?php if(this is the Country you selected)echo 'selected="selected"'; ?> >The Country</option> 
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.