Add Category To Custom Post Type

After several times search for how to add category into custom post type with no luck, i try to create it by my self based on the available code at the premium themes.

The code is very simple, you just have to put this code into your functions.php

function our_new_taxonomy(){
  register_taxonomy('affiliate-category', 'affiliate', array('hierarchical'=>true,'label'=>'New Affiliate Category'));
}

And this is the explanation of the code:

  • affiliate-category: This one called by post tag, the name is up to you (since my custom post type name is affiliate, then to make it simple i create affiliate-category)
  • affiliate: This one is your custom post type registered name
  • New Affiliate Category: This one is the label which will be displayed at WordPress Dashboard

Simple isn’t it?

Advertisements

31 thoughts on “Add Category To Custom Post Type

  1. Terrific work! That is the kind of info that should be shared around the web.
    Disgrace on the search engines for now not positioning this publish higher!
    Come on over and consult with my site . Thank you =)

  2. I’ve been browsing online more than 3 hours
    today, yet I never found any interesting article like yours.
    It’s pretty worth enough for me.
    In my view, if all web owners and bloggers made good
    content as you did, the net will be
    a lot more useful than ever before.

    • hi, right now i’m using WordPress based blog (WordPress.com – hosted on WordPress.com site). If you want to have a risk free site like security, etc, you can use WordPress and install a firewall plugin

  3. Good day! I could have sworn I’ve visited this site before but after looking at many of the
    posts I realized it’s new to me. Anyways, I’m certainly pleased I stumbled upon it and I’ll be book-marking it and
    checking back frequently!

  4. Having read this I thought it was very informative. I appreciate you spending some time and
    energy to put this content together. I once again find myself personally spending a significant amount of time both reading and leaving comments.
    But so what, it was still worthwhile!

  5. I must thank you for the efforts you have put in writing this site.
    I am hoping to see the same high-grade content
    from you in the future as well. In truth, your creative writing abilities has
    encouraged me to get my own website now 😉

  6. I wanted to thank you for this excellent read!! I certainly enjoyed every little bit of
    it. I have you book-marked to look at new stuff you post…

  7. I’m impressed, I have to admit. Rarely do I encounter a blog
    that’s both equally educative and engaging, and let me tell you,
    you’ve hit the nail on the head. The issue is something too few men and women are speaking intelligently about. I am very happy that I came across this during my search for something regarding this.

  8. hello there and thank you for your information – I have certainly picked up something new from
    right here. I did however expertise some technical points using
    this site, as I experienced to reload the site lots of
    times previous to I could get it to load correctly. I had been wondering
    if your hosting is OK? Not that I’m complaining, but sluggish loading instances times will very frequently affect your placement in google and could damage your high-quality score if advertising and marketing with Adwords. Anyway I am adding this RSS to my e-mail and could look out for a lot more of your respective intriguing content. Make sure you update this again soon.

  9. Thank you for this blog site pertaining to ColorLabs themes. The addition support is appreciated.

    In regards to this post, I’m not exactly sure what the function of this code is. What exactly can I do using this code? Does it allow me to display photograph categories in a gallery?

    I’m using the Lensa theme and love it! However, I can’t seem to figure out how to create gallery pages that display only one photograph category. Right now, when I create a gallery page named Animals, I can select either Post or Photograph as the gallery source. When I select Photograph it only displays all the Photographs I created but not just the photos from a specific category, i.e.-Animals.

    What I’d like to do is create 4 different gallery pages (Animals, Events, People, Scenic) with each displaying only the photographs from the respective category. So, for the Animals gallery page, I want to show only the animal photographs. Is there any way to do this with the Lensa theme?

    Thank you in advance for any advice you might have.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s