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

  • | |

    Random Code Generator 1.0

    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!A couple of weeks ago, when I officially launched the redesign, I mentioned the forthcoming release of a plugin I wrote…

  • | | |

    Version 4.0

    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!The New TehJoey is officially launched. You may have been noticing over the last few days, when layouts were switching back…

  • |

    Should You Really Write in the WordPress Editor?

    While WordPress made it’s reputation on being a blogging platform, the writing experience has never been idea. Now, the block editor has made the writing experience…different. But that begs the question: should you ever write in the WordPress editor?

  • |

    WordPress Helper Functions for Detecting IE

    The other day I was working on a problem where I wanted to check if a website was using a specific browser (in this case IE) and version (in this case 9 or below). I came up with 2 functions that would serve an a nice, reusable check for both. These can also be extended…

  • |

    Win a Free Ticket to WP Summit!

    Last week I talked about the tail end of my speaking tour (thanks to everyone who came out to @WordCampPhilly). Up next is @WordCampChicago, but I’ll also be speaking at the WP Summit 2014, an online conference, on Wednesday, June 18th and I want to give away a free ticket!

  • |

    Quick Tip: Custom Category Styles 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!Over the weekend I revamped this blog’s current theme a little bit, including adding custom styles for my Link Round-up lists….

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.