WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] When to use Custom Taxonomies instead of Custom Fields? (6 posts)

  1. travelvice
    Member
    Posted 3 years ago #

    Since 2005 my travelogue has been using a custom field ("location") to hold the city (or beach... ;D) that the entry was written from -- "Lima", in Peru, for example.

    As I'm in the process of upgrading this ancient version of WP to 3.1, I'm trying figure out if this field should be converted to a custom taxonomy.

    Advantages for this type of stored information? Disadvantages? Not at all necessary?

  2. Curtiss Grymala
    Member
    Posted 3 years ago #

    If the data is normalized in any way, it probably makes more sense to use a custom taxonomy as opposed to a custom field. Custom taxonomies are easier to query against than custom fields; it's simpler to set up archives of custom taxonomies; etc.

    However, if most of the values are one-off type of things (unique to each post/page), it makes more sense to use a custom field.

    The main disadvantage of trying to convert a custom field to a custom taxonomy is simply making sure the old data is consistent before trying to make the conversion. If your users have typed "Lima", "lima", "Lima, Peru", "lima, peru" and "Lima Peru" into the custom field - all intending to be the same thing - it's going to be difficult to format all of that data properly before importing it.

    The other disadvantage to using a custom taxonomy is that, ironically, it's much more difficult to validate (and therefore ensure consistency) the values entered into a custom taxonomy than it is to validate the entries in a custom field.

  3. travelvice
    Member
    Posted 3 years ago #

    Interesting!

    Validation isn't an issue -- single user (me) and it's just the city name (eg Lima) as the country is the category. The data is very much normalized.

    Would you say, in crafting a custom select query, that the lookup for posts with a specific taxonomy is less process intense or more process intense as a query (as compared to the same lookup with a custom field)? Is there a performance advantage?

  4. Curtiss Grymala
    Member
    Posted 3 years ago #

    I can't say with any certainty, but it looks like the custom taxonomies should be less intensive than the custom fields.

    Custom fields are stored as meta data in the postmeta table. Each row in that table contains a unique ID for the meta entry, the ID of the post to which the meta data belongs, the meta key and the meta value (which can be an integer, a string or a serialized array). Assuming the meta value is a simple string or integer, the difference is probably minimal; but if the meta value is an array, you would have to retrieve the entire meta value and process it before you could run any comparisons.

    The terms, however, are all stored in their own table. Each row in the term_relationships table has the ID of the post to which it's related, the ID of the term itself and order in which the term should be displayed (if applicable). Therefore, it can be more easily compared.

    Again, since your custom field values all appear to be simple strings, the difference between comparing the custom field value and comparing a custom taxonomy value is probably negligible (though, I believe there is a tiny bit of advantage comparing integers instead of strings); but if you were collecting serialized data in your custom fields, the custom taxonomies would give you a huge advantage.

  5. travelvice
    Member
    Posted 3 years ago #

    Fantastic information for myself & others searching for thoughts on the same subject! Thank you, Curtiss!

  6. ldexterldesign
    Member
    Posted 3 years ago #

    @Curtiss Grymala cheers mate. Been after a simple answer to this question for about 12hrs. Surprising nobody in the #wordpress irc was capable :/

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.