0

I have a custom post type called newsletter. At the same time, an implemented analytics tool (not related to my CPT) uses newsletter as a GET parameter to track some incoming links (and I can’t change this).

Say, I have

https://www.example.com/?newsletter=value_for_analytics_tool

This will lead to an 404 error page, as WordPress obviously tries to find a post in my newsletter CPT. But actually, I just want the main page to show up and keep the newsletter parameter for the analytics tool.

Is there any way to 'ignore' GET parameters, but keep my CPT working?

0

You should always preface your CPT names with something to avoid stuff like this - common naming leads to conflicts. My recommendation, so that you avoid this happening again would be to go and re-work your CPT code in your plugin/theme and use myplug_newsletter as the name of your CPT. Obviously change the myplug_ to something unique to you.

| improve this answer | |
  • 1
    Hi Tony, thanks for your answer! You are right in saying that one should check things for naming conflicts. In this case, my CPT was there first and then my customer implemented their tracking tool by themselves. And now it’s my honor to fix this again. :-/ So I was hoping to find a solution other than renaming my CPT, as there are many things connected to that. Something like "if there is newsletter as GET parameter in the URL, just do nothing and keep the param". I found this on the web: stackoverflow.com/q/19030021, but unfortunately this will break my whole CPT. – mischnu Jan 30 at 7:51
  • 1
    Sorry, I made the assumption that you were still in the early development stages and didn't realize the site had already been up and running. – Tony Djukic Jan 30 at 13:49
  • The answer in the link you posted is taken pretty much from here: codex.wordpress.org/Plugin_API/Filter_Reference/request I think you'd be able to modify that so that the request modification only executes if it's NOT loading your CPT. So check if the query is looking for 'post type'=>'newsletter' and if not, run the filter. – Tony Djukic Jan 30 at 13:55
  • this is not an answer. the issue can occur with any literally any post type name. its a legitimate issue that i haven't personally experienced but a proper solution would be nice. – Joel M Jan 31 at 3:02
  • 1
    Thanks this did the trick. – Nelles Jan 31 at 16:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.