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

  • | |

    Testing Code Blocks with Ulysses

    Over on Twitter, Tom McFarlin asked me if Ulysses supports code syntax when pushing to WordPress: https://twitter.com/tommcfarlin/status/1526909277352480769 So I decided to give it a test: Looks good! And here’s what it looks like in Ulysses:

  • |

    Why Pro Bono Work Hurts Everyone

    It’s something that has happened to everyone who’s a freelancer, or perhaps just everyone who runs a business. People will ask for things for free; I want to make it super clear now that I’m not saying never do pro bono work. I’ve done it. It just needs to be the right circumstances; asking a…

  • | |

    Directory Handler at Theme Forest

    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!I’m happy to announce my first Theme Forest component, Directory Handler. it’s a simple set of 2 classes that handle (in…

  • |

    WordPress 5.0 Has Been Delayed – What Now?

    If you haven’t been following the dev chats in the WordPress Slack team, there’s a lot of confusion around exactly when WordPress 5.0 will ship. Release Candidate (RC) 1 is out now, and RC2, as I write this, is around the corner. These should signal that the answer is “soon” but there has been no…

  • Quick Tip: Check to See if a Slug Exists in WordPress

    Recently I was doing some work where I was importing RSS entries into a Custom Post Type in WordPress. Since there were no common IDs between the feed and WordPress, to prevent duplicate entries I tried comparing titles. This also proved to be an issue as titles aren’t always unique, and they weren’t in this…

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.