[wp-hackers] Category/Tag/Taxonomy Meta Data

Glenn Ansley glenn at glennansley.com
Mon May 31 22:25:31 UTC 2010


Hi Nathan,
I like you're idea about using the taxonomies tables (via twitter).
What about something like the following:

On plugin activation or another 'fire once conditional', create 1) a
custom taxonomy and 2) terms in that custom taxonomy (for your custom
fields):
* register_new_taxonomy( 'my_tax_custom_fields', $args );
* wp_insert_term( 'field_name', 'my_tax_custom_fields, $args );
* wp_insert_term( 'field_two_name', 'my_tax_custom_fields, $args );

Then, on creation / edit of category or ( hooked into
{taxonomy}_edit_form_fields ):
* wp_set_object_terms( ID_OF_Cat/Term_Just_create_or_modified,
array('field_two_name'), 'my_tax_custom_fields' );

Then, to retrieve that information when displaying in theme or for
updating data, you could use:
* wp_get_object_terms( ID_OF_Cat/Term_Just_create_or_modified,
'my_tax_custom_fields', $args );

That is very rough and not tested but it would theoretically
accomplish the following:
* Keeps values out of options table
* Add's values to wp_term_taxonomy table

Possible cons:
* You're actually creating more database calls and PHP code by keeping
it out of options table
* Possible clash of post IDs and term IDs if some foreign code assigns
your custom taxes to a post rather than another taxonomy for some
reason.

That would do probably do it. I'm sure there's a hurdle in there
somewhere I didn't foresee... although after processing this, I'm
really wondering if its worth the trouble to remove data from the
options table. Why do you want to do that?

The best solution would be a new table called wp_taxonomymeta ;)

Glenn Ansley
http://fullthrottledevelopment.com
http://twitter.com/glennansley

On Mon, May 31, 2010 at 5:22 PM, Nathan Rice <ncrice at gmail.com> wrote:
>
> I notice that there is an action hook that allows you to add extra form
> fields to the Edit Category/Tag/Tax page, {taxonomy}_edit_form_fields, which
> is VERY cool. But this action hook seems pretty useless unless the new form
> field you insert actually allows you to save some extra data.
>
> For instance, let's say that I wanted to add another textarea that allowed a
> user to insert a "short" description of the category to be used somewhere in
> the theme. I can figure out how to insert the form field, but I can't figure
> out why the data won't actually save. I imagine there's some sort of
> sanitization going on that limits what can and can't be saved, but is there
> any way to bypass that?
>
> Bottom line ... is there any way to add extra fields of data, without
> resorting to storing this data in the options table? We have this sort of
> thing in place for posts (postmeta), comments (commentmeta), and users
> (usermeta), but it would be cool if it could be done with taxonomies too.
>
> Thanks!
>
> ------------------
> Nathan Rice
> WordPress and Web Development
> www.nathanrice.net | twitter.com/nathanrice
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers


More information about the wp-hackers mailing list