Fixing the Fatal ‘add_rewrite_tag()’ Error

I’m working on a WordPress little side project where I am registering a new Custom Post Type and Taxonomy and came across this:

 Fatal error: Call to a member function add_rewrite_tag() on a non-object...

After doing a Google Search to try to figure out what the issue is, all I came up with was “disable all of your plugins and reenable them to see which is the bad one.” That doesn’t help me because I know the one I’m developing is the bad one. My next step was just do to a Find for the term ‘rewrite’ and wouldn’t you know it, I came up with the the solution.

As it turns out, I was trying to register the taxonomy for my CPT before actually registering the CPT. If you ever run into the error yourself, try moving ” register_taxonomy” onto the line directly under the link that has “register_post_type.” My code was below it, but due to certain hooks I called, register_taxonomy was getting called first.

You might also want to prefix your taxonomies and CPTs; conflicts can arise that may also lead to that error. Happy Coding!

Similar Posts

  • Caring Enough to Give Back to Your Community

    People who know me probably know a few tenets of my character: I can get very passionate about things, I like doing stuff (to the point where I say yes too much), and I give back where I can. Over the weekend, I hosted an event called the NEPA Hackathon and it was a lot of fun….

  • | |

    Create a Temp/Splash Page in WordPress

    Note: This article was published while I was in my early 20s. I was much younger and dumber. Please don’t hold it against me. One of the perils of having a 20+ year old website!Often times I will be working on a WordPress theme that I want to live test, but I don’t want to…

  • | |

    Deleting 3 Million Spam Comments from a WordPress Database

    Over at the Crowd Favorite blog, I wrote up a post about an interesting problem I solved recently. I laid out everything you need to know there, but it involves downloading a HUGE database and putting WP-CLI to good use. If you haven’t used it before and you do development with WordPress, it’s super valuable….

  • |

    Announcing WP in One Month

    I’m passionate about is teaching. I speak at conferences, write tutorials and books, developed and teach courses. Last week, An Event Apart hosted a Front End Development Round Table and the question, “What makes a senior developer,” came up. The general feeling was someone who can do and teach makes a senior developer. This reinforced…

  • |

    How to Learn a New Programming Language

    Note: This article was published while I was in my early 20s. I was much younger and dumber. Please don’t hold it against me. One of the perils of having a 20+ year old website! As I said in the last two posts, Google I/O was truly inspiring. It got me to thinking about how…

  • The coding process

    Note: This article was published while I was in my early 20s. I was much younger and dumber. Please don’t hold it against me. One of the perils of having a 20+ year old website!During my winter break, which is very quickly coming to a close, I have done a lot of coding- stuff I…

One Comment

  1. I also kept finding the same “Disable plugins” lol, not much help when you’re the dev. Much appreciated!

Comments are closed.