Let’s say for (a classic) example that I want to create an event custom post type, which will have assigned some specific fields/properties. One of them: location venue.
Location venue, which I’m thinking should be a tag in a custom taxonomy, would have, besides the title, also an url and a pair of coordinates, for example.
So, questions are:
- Would this be a sensible approach?
- How would I go implementing it?
This sounds like a good idea as it would let you query by location etc. I don’t know what you plan to use the co-ordinates for, but it makes no sense to have them attached to an event (unless that event is a one-off in the middle of a field, but I guess that would be an edge case?).
As for implementation, this is a very useful plugin:
http://wordpress.org/extend/plugins/taxonomy-metadata/
It allows you to add/get/update/delete term meta just as though it were post meta
So you could do something like this (just to give the idea, may not work 100%) :
to set the information, and then use $_POST to update the meta thusly:
Further reading: http://en.bainternet.info/2011/custom-taxonomies-extra-fields
As others have already said, no, terms can not have additional properties attached to them. A term in a taxonomy is just a label for a group of items.
So, I would instead make venue a second custom post type and then connect it to the event post type using Posts 2 Posts: http://wordpress.org/extend/plugins/posts-to-posts/
The coordinates could be added using metaboxes. Check out the example here http://codex.wordpress.org/Function_Reference/add_meta_box#Example
What you’re wanting is term meta data, e.g. two events are tagged at “The Big place”, and “The Big Place” has coordinates etc attached to it, that are pulled in by the two events.
Unfortunately WordPress does not have a facility for term meta. You can add it via plugins, alternatively, you could have a post type location-meta, set up to not be public and not show in public listings, that you can attach the meta to, then assing it to relevant term tag.
Or you could make your taxonomy heirarchical, and add child terms with names such as ‘coordinates-X-Y-Z’ etc and filter them out when viewing the taxonomy terms.