Timeline for Permalinks not working for custom taxonomy on custom post type
Current License: CC BY-SA 3.0
4 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Jan 1, 2017 at 19:56 | comment | added | Michael Ecklund |
You have a function which registers your Custom Post Types and Custom Taxonomies. Both are hooked on the action init . The register_activation_hook() function is called BEFORE the init hook is fired. You're flushing the rewrite rules before the the rewrite rules even exist. In the callback function which is triggered on plugin activation, make a call to your function which is used to register your Custom Post Types & Custom Taxonomies. Immediately after that, make a call to flush_rewrite_rules(); . That way, your rewrite rules are created and WP is aware of them upon plugin activation.
|
|
Jan 1, 2017 at 19:49 | comment | added | Joshua Goossen |
I was flushing on activation and deactivation. This says that calling this function on init is bad practice. codex.wordpress.org/Function_Reference/flush_rewrite_rules
|
|
Jan 1, 2017 at 16:01 | comment | added | Michael Ecklund |
You're right about my answer. It's pretty much a pointless answer so I've removed it. Probably shouldn't have been answering while distracted. You should flush the rewrite rules on plugin activation AND deactivation and AFTER your Post Types / Taxonomies have been registered. Easy way around it is to have a callback function to be called on init which registers your stuff. On plugin activation, call that init callback function and then immediately flush rewrite rules after. If you have a plugin settings page, you could also implement rewrite rule flushing when saving plugin settings page.
|
|
Dec 31, 2016 at 23:57 | history | answered | Joshua Goossen | CC BY-SA 3.0 |