WordPress.org

Ready to get started?Download WordPress

Forums

Add custom taxonomy to "Links" (aka bookmarks) (5 posts)

  1. guitavares
    Member
    Posted 5 months ago #

    I enabled the Links Manager in my wordpress installation.
    I use the Links as a way of managing banner ads. By using Link Categories I can display specific banners on the right place of the site.
    What I am trying to do is to register a custom taxonomy ("clubs") to the Links post type (BTW: are "Links" a regular post-type just as "posts" or "pages"?)
    I am trying to do this so I can extend a taxonomy I use on posts, to also be used on Links, this way I can relate posts to links and display the right ads for my post sidebar, based on the same taxonomy they share.
    I tried using the function: register_taxonomy_for_object_type('clubs', 'links') but it does nothing. (I tried using links, link, Links, Link in the post_type parameter as well). 'clubs' is the correct name of a custom taxonomy I have already registered (via plugin).
    I am also attaching that register function to the 'plugins_loaded' hook, so to make sure my 'clubs' taxonomy is correctly created by my plugin when I try to extend it to the Links.
    I can't seem to find much help about this online, especially because the words "links" and "taxonomy" on my search terms return mainly other kind of topic that is not what I am trying to solve, so I created this topic.
    Any help?

  2. bcworkz
    Member
    Posted 5 months ago #

    Links are not a full fledged post type. They are in their own table similar to comments or users. But sometimes they can be referred to as though they are a post type with success.

    The link category is a different taxonomy then the post category, but it IS a taxonomy, so some ability exists to assign taxonomies to to links, but register_taxonomy_for_object_type() doesn't work because "object type" is really some sort of post type. WP registers Link Category taxonomy with register_taxonomy(), so I would expect you can register your own taxonomy the same way. Thus it cannot be an existing taxonomy, it must be registered new for the 'link' pseudo post type.

    If you need to use the same taxonomy for other post types, you might be able to use register_taxonomy_for_object_type(), or not. Try it and see :)

    For reference, Link Category is registered by create_initial_taxonomies() in taxonomy.php. You will want to register yours from the 'init' action.

  3. guitavares
    Member
    Posted 5 months ago #

    Thanks a lot, that was clarifying. I'll try it and see.

  4. guitavares
    Member
    Posted 5 months ago #

    Actually after reading it again I think I should create a custom post type called "Banners" and forget about the Links manager. This way I can use shared taxonomies in their full glory with no issues.

  5. bcworkz
    Member
    Posted 5 months ago #

    I'd say that's a very good decision!

Reply

You must log in to post.

About this Topic