I have a form, created as a plugin in wordpress. In the form is a drop down select menu that is populated with all entries from a custom post type called ‘singers’.
i.e. “singer 1, singer 2, singer 3”
In this custom post type, each singer has meta box info, the info I’m interested in is ‘singer_gender’. When a singer is selected, I want to pass a variable into a hidden field on that form with either “male” or “female”
So, for example, if Singer 1 is selected, and is male, my form would have the following hidden field:
<input type="hidden" name="singer_gender" id="singer_gender" value="<?php echo singer_gender; ?>" />
Is there a way to make this happen?
You would use
get_post_meta
to retrieve values entered in a meta box.If
singer_gender
is the meta box key, your code might look like this:You could store the gender inside a data value on the options of the select.
Like this:
To generate the HTML for that use get_post_meta