I have a custom post type ('Model'
) for a sports modelling agency, and it requires the model to enter sports they are competent at, and also rank their ability from 1 to 5. For example, given the information:
Model: Joe Soap.
Football: 4.
Archery: 2
I would store this in the custom_post_type 'model'
with the fields:
Model Name: Joe Soap.
Sports: Football, Archery (taxonomy).
Rank: 4, 2.
How do I associate 4
with Football
and 2
with Archery
using a metabox, where different models may have different sports in their lists ?
Your question is focusing on the wrong thing. A metabox is just one way for a user to introduce some data. The more important question is how you should store that data in the database.
You could make ‘sport’ a custom post type and connect it to models using the Posts 2 Posts plugin. Then, for each connection, you can associate a ‘rank’ custom field:
https://github.com/scribu/wp-posts-to-posts/wiki/Connection-information
The plugin takes care of creating a metabox and of storing the values in an efficient manner.
add_meta_box()
documentation in Codex has example of metabox creation and links to related tutorials.This tutorial on adding custom meta boxes is also really good: http://webdesignfan.com/custom-write-panels-in-wordpress/
It’s all very flexible; you should be able to reuse the code you create.