Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am new in here. Hope that you guys can help me.

Few days ago, I posted the same question on Wordpress.org support forum, however till now no one answer me, not even 1 reply. Maybe my issues is too complex, or too stupid. So be gentle.

Here is my questions:

For the custom fields, can we defined Parent and Child value option? The child value options are depend on the Parent input.

For example when we adding an address:

Country : [US, CN]

If the user choose US then the next custom field is State and the value options would be The states in US . Country -> [us] State : [Alabama,Alaska,American Samoa,Arizona,Arkansas...etc]

However if user choose CN, then the next custom field would be Province and the value options would be the provinces in China

Country -> [CN] State : [Anhui,Beijing,Chongqing,Guangdong,Shang Hai...etc]

Hope you guys know what I tried to express..

The plugin that I use for create the dropdown custom fields is Custom Content Type Manager. I wonder if I able to hook jquery to custom fields area to make it happens? If it is possible to do so, how? Any guides to help me solve this would be appreciated.

share|improve this question

1 Answer 1

up vote 0 down vote accepted

This is doable, the meta data itself has no heriarchy, they're simple key value pairs attached to a Post ID, nothing more. You would be ebtter implementing these yourself via metaboxes, rather than relying on a dedicated generic plugin as you have been doing. It would take you a lot more time and effort to retrofit the plugin you're using than it would be to simply write your own metabox.

For details on how to create your own metabox and save the details, see this codex page with code examples:

http://codex.wordpress.org/Function_Reference/add_meta_box

Doing this, I would have a dropdown for the country, followed by a set of dropdowns for each province/state hidden and shown by jquery.

Although I would much rather use a single combo box and use grouping instead and store both the country and the state/province/county in the value.

e.g.

<select id="location" name="location">
    <optgroup label="United States">
        <option value="us_virginia">Virginia</option>
        <option value="us_alaska">Alaska</option>
        <option value="us_texas">Texas</option>
        etc...
    </optgroup>
    <optgroup label="United Kingdom">
        <option value="uk_london">London</option>
        <option value="uk_devon">Devon</option>
        <option value="uk_yorkshire">Yorkshire</option>
    etc...
    </optgroup>
</select>
share|improve this answer
    
Thanks Tom for such quick reply. Yes, I know it's better to use metaboxes. However, I need to create a lot of custom fields. It would be easier to use a plugin to generate those fields. My idea is using jquery to control the options. Since the dropdown options only accept one set of values, so I have to manually create other values list (in themes function.php) like the example you gave, and using jquery to override old valuse. I don't know this method will work or not, please give advice. –  dev-jim Mar 30 '12 at 16:47
    
You don't have to use the plugin for all of your fields, and vice versa, you can do both –  Tom J Nowell Mar 30 '12 at 19:41
    
Use a manual metabox for fields like this dropdown, and use your plugin for everything else –  Tom J Nowell Mar 30 '12 at 19:41

Your Answer

 
discard

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.