Link to home
Start Free TrialLog in
Avatar of steva
steva

asked on

Understanding Taxonomies

As I understand the term, "taxonomy" is just a way to group your posts, like "products." You can indicate your post is  a "product" by specifying "product" as a taxonomy of the post in wp_insert_post().  But you could also just add a custom field to the post, like "group=product" and then to get all the product posts, ask for all the records that had a custom field of group whose value was product.   I'm assuming, though,  that the latter method would require WordPress to look through all the posts for those that had a custom field of group whose value was product, while the taxonomy method essentially threads all the records together that have the taxonomy product so they're accessed directly instead of through a search through every post.  Is that correct?

Second, is "category" a built  in taxonomy?  So that if I assign a category of product when I do my wp_insert_post() then when I ask for all records with category =product,  will  WordPress  be able to access all the product posts directly, i.e., all the posts with category=product?

Thanks for your help.
ASKER CERTIFIED SOLUTION
Avatar of Jason C. Levine
Jason C. Levine
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of steva
steva

ASKER

Thanks Jason for the great answer and reference. The main take-away from the article for me is that finding records with a given taxonomy is very fast because they're all linked together, while finding records with  given custom field is much slower because WordPress has to look at every record and see if it has the desired custom value.  

That makes me wonder if custom post types are linked.  If you ask for all records that are a custom post type,  does WordPress have to look at every record and check it's type, or is there a linked list of records for each custom post type?

In my case, an input form collects data from the user and creates a post with that data, storing many of the fields into custom fields.  A "listing" page then needs to pull all of these posts and place them into a table that gets displayed,  where the columns of the table are basically the input fields of the form.  To make it easy to pull just these records from the DB I think I'll make them a custom post type.  Hopefully WordPress can follow a linked list for this post type and go right to each record, instead of looking at all the records and seeing if it's the right post type.  

Thanks for your help!
The main take-away from the article for me is that finding records with a given taxonomy is very fast because they're all linked together

Sort of.  It's faster because of how the term tables are structured in MySQL.

while finding records with  given custom field is much slower because WordPress has to look at every record and see if it has the desired custom value.  

Custom Fields are stored in wp_postmeta.  So every custom field query basically selects the name of the custom field and then compares against the value related to that time for each record. This would be fractionally slower than a terms search, mainly due to indexing and performance in the abstraction layer (the wp_select_whatever functions).

That makes me wonder if custom post types are linked.  If you ask for all records that are a custom post type,  does WordPress have to look at every record and check it's type, or is there a linked list of records for each custom post type?
SELECT (whatever) FROM wp_posts WHERE post_type = 'name of cpt'

Open in new window


That's typically a very fast search and if you index that column, it goes even faster.  The Loop is the abstraction layer between you and that SQL statement and it's also been optimized for speed and memory usage.