sulmanpucit
sulmanpucit

Reputation: 456

dynamic WordPress custom meta boxes

I'll try and give an example what i want:

(this isn't what I'm doing, but it seems like a decent example of how I'd like it to work)

Imagine we have a custom post type (CPT) of 'houses' and one of the custom meta options for this CPT is 'bedrooms' - obviously, different houses have different amount of bedrooms, all of which have different properties. So, I'd like to be able to allow the user to add several different properties about a bedroom i.e.

Dimensions, aspect, number of windows and floor type

When the user has added these details for the first bedroom, if the house has a second bedroom then I would like them to have an 'add bedroom' button and another set of these meta boxes is added so they can fill out the details about bedroom 2.

I understand that I'll need some javascript to add this facility (and something I don't mind writing) but what I'm struggling with in my poor, useless brain is how to save these to the database. I want to achieve this using WordPress meta so that I don't add any unnecessary database tables and I'm sure it's possible I just can't quite fathom the principles of how to save the data.

Pointers to any tutorials would be brilliant, or some examples of plugins which already do this kind of thing would be very gratefully received. here is a screenshot to get an idea what i want to do. enter image description here

Solution: I have found solution here, it might be helpful for someone. https://wordpress.stackexchange.com/questions/25478/custom-post-type-metabox-array

Upvotes: 2

Views: 3873

Answers (1)

noponies
noponies

Reputation: 2726

You are basically after repeater metaboxes. A few metabox classes support repeating fields. One worth checking out is http://www.farinspace.com/wpalchemy-metabox/

I wrote a plugin that uses repeating metabox fields that doesn't use wp-alchemy if you want to dig through it. http://code.google.com/p/css-thumbnail-sprites/

Upvotes: 2

Related Questions