I cannot be 100% sure since I can’t test without installing and running you code but I think the problem is that you aren’t echoing your selected
markup.
<option <?php selected(
get_post_meta($post->ID, 'cpi_dropdown_options', true),
'Option 1',
true
); ?>>No</option>
The last parameter tells selected
to echo output.
Edit:
Your options aren’t sending a value. Compare your code to this code from the Codex:
<option value="1" <?php selected( $options['foo'], 1 ); ?>>1</option>
Your code is missing the value=
part. You claim that:
…if I create a post and set the option to Yes, then I go edit to
post it shows No but in the custom meta field it does show Yes so it’s
saving correctly. I know that the No and Yes values should be dynamic
and check if any custom meta has been set to display it but not sure
what the code is.
That sounds as if you have verified that things are actually saving to the database as you want but without that value
part I don’t see how they could be. That is, without the value
part your form is sending the option contents– ‘No’, and ‘Yes’. You can verify that with this little snippet:
<form>
<select name="hi" method="get">
<option>No</option>
<option>Yes</option>
</select>
<input type="submit" value="go" />
</form>
However, you are looking for true
values of “Option 1” and “Option 2”. You can either add the value
attribute to match what selected
is looking for, which is probably best because you can then alter the outward appearance of the form without altering the function of the form, or you can check for “No” and “Yes” instead of “Option 1” and “Option 2”.