We help IT Professionals succeed at work.

Understanding Taxonomies

steva
steva asked
on
39 Views
Last Modified: 2016-01-25
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.
Comment
Watch Question

Don't talk to me.
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
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!
Jason C. LevineDon't talk to me.
CERTIFIED EXPERT

Commented:
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.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.