[wp-trac] Re: [WordPress Trac] #4189: Taxonomy Schema and API
WordPress Trac
wp-trac at lists.automattic.com
Thu Apr 26 00:10:00 GMT 2007
#4189: Taxonomy Schema and API
-------------------------------------------+--------------------------------
Reporter: ryan | Owner: anonymous
Type: defect | Status: new
Priority: normal | Milestone: 2.3
Component: General | Version: 2.2
Severity: normal | Resolution:
Keywords: term taxonomy tags categories |
-------------------------------------------+--------------------------------
Comment (by majelbstoat):
That being said, here is a basic schema (still with the parent column) and
the beginnings of a WPTaxonomy class. I stayed away from WPTerm, because,
even though it is a nice construct, you don't want to have to create a new
instance of a term every time you want to do an operation. Taxonomies are
stored in a separate table for permanence, but will be retrieved from
get_options for minimal db impact. I think that's what was agreed on on
the list? is_int() is used to distinguish between term_ids and
term_slugs.
add_term_relationship() is worth a mention as it is designed to be quite
flexible. It can take an array of term ids or slugs, an object_id and an
array of taxonomy ids or taxonomy slugs. It should create the terms that
don't exist (though, in general this shouldn't be required), then create
or increment the term-taxonomy relationship (inefficient at the moment as
it is db queries in a loop), then finally create the object-term-taxonomy
relationships. An example call might be
{{{$wp_taxonomy->add_term_relationship(array('cities', 'vacation', 5), 3,
array('post_category', 'post_tag'));}}}
Which would add both tags and categories for cities, vacation and the term
with id 5 to the post with id 3. The eventual idea is to be able to add a
whole load of taxonomy to an object with only one or two queries, rather
than repeated calls for each category/tag etc. I'm thinking this will be
a very common case, for example when saving a new post. To realise this
fully, add_term_taxonomy() will have to be modified to accept arrays as
well, so that we don't end up calling 3 queries per term per taxonomy.
This is just a starting point - possibly misguided and probably buggy, but
it's something to work from...
Cheers,
Jamie.
--
Ticket URL: <http://trac.wordpress.org/ticket/4189#comment:2>
WordPress Trac <http://trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list