Leave a Reply

3 comments

  1. You can add taxonomy metadata, similar to add_post_meta and some examples of doing so include,

    Tutorial Walk-Through

    Taxonomy Metadata Class (improved version of above)

    I have personally used this class myself which was also authored from a reputable member and moderator here at WPSE -> Bainternet, it did what it said on the box.

    Plugin

    Tutorial Walk-Through

    That aside…

    If you have a user, named Jack for instance, then why don’t you assign the user to the custom post type via a post meta field in a meta box?

    So you’d be looking at,

    add_meta_box

    add_post_meta

    You can still use custom taxonomies to help you further classify or group your data, but a lot of what you are trying to achieve is quite simply the same as if you were doing it with posta meta data to begin with (i.e. add_post_meta)

    And to simplify things, you can you a meta box class to roll out your solutions,

    http://en.bainternet.info/2012/how-i-add-a-wordpress-metabox
    http://www.deluxeblogtips.com/meta-box/
    http://www.farinspace.com/wpalchemy-metabox/

    I have used all of the above, each of which are good. I still use WPAlchemy and the Meta-Box class from Deluxe Blog Tips. As for Bainternet’s, there’s nothing wrong with that class, its a matter of using too many already. So take your pick.

    UPDATE

    My approach to this would be to,

    • a) create a custom post type Birds
    • b) create a taxonomy Bird Type
    • c) create a meta box with two fields

      • 1) lists users in a drop down
      • 2) name of users bird

    The process would be to,

    • a) add a Bird, such as Canary
    • b) add a taxonomy term that matches the name of the bird, e.g. Canary
    • c) add a user in my meta box associated with this bird
    • d) if available at the time of creation, add the given name the user chooses for the bird

    Using a repeatable field that has an Add Now button, you can add another user. But instead of grouping all of the meta fields into one post meta_key, you need to create separate post meta keys for each user you wish to associate with the bird, otherwise you’ll end up with serialized data which is slow to query.

    Even this approach can be improved.

    You could instead associate the Taxonomy “Canary” to the user via User Meta instead.

    For each type of bird in the users collection, you would use add_user_meta to apply a name the user chooses for the bird.

    Your meta box that you create via add_meta_box isn’t strictly limited to using add_post_meta etc functions, you could write your function to use add_user_meta and update_user_meta instead. So on and so on.

    This leaves clear separation between each of your elements.

    • Custom Post Type is for the Bird which might explain the bird, its origin, etc
    • Taxonomy is for the classification of the Bird
    • Meta Box / User Meta function is to associate Taxonomy and given name of Bird to user

    The post_parents idea really isn’t a good one, I have to say, because creating a new Post for what is otherwise meta data in the first place equates to bloat when we already have the Taxonomy and User tables to go along with the Posts table for your custom post type.

  2. I don’t see much of an issue besides that there can only be one post parent. Using a posts-to-posts type of relationship, which allows for many-to-many, would be an alternative route, where your “taxonomy terms” are really posts of a custom post type and thus can have content (and even taxonomies, etc.) associated with them. The lovely Posts 2 Posts plugin makes this much easier to accomplish, and with UI to boot.

  3. As of WordPress 4.4, Taxonomy term meta is now a part of WordPress core.

    You can use the following new functions to manage term meta:

    However, for the particular use case in this question, the most robust way to manage User relationship with a Post may be to use Posts2Posts (plugin created and maintained by scribu, a core contributor).

    Using this plugin, you can create a relationship between a User and a Post and also add meta data to the relationship itself.