OK, I had to debug it and… Everything is just fine with your code. Almost everything.
When I click the Publish button, I get that error:
A post type mismatch has been detected
And if you’ll take a look at your form, you’ll see why…
In your form you have this field:
<select name="post_type" style="width: 200px;margin-right:20px;">
post_type
name is already used for different purposes. So your field overwrites it and is causing the error.
There are some names that you should be avoided, when you create your own meta boxes. And the best idea is to prepend your fields with some prefix to make sure, you’re not causing any conflicts.
So if you add ttl-to-edit
meta box, I’d call all the fields like ttl-to-edit-post_type
or something like this. Sometimes it’s convenient to put them in an array like ttl_to_edit[post_type]
.
PS. You should NEVER put flush_rewrite_rules
in init hook – it will cause major performance issues.
- Flushing the rewrite rules is an expensive operation, there are
tutorials and examples that suggest executing it on the ‘init’ hook.
This is bad practice. It should be executed either on the ‘shutdown’
hook, or on plugin/theme (de)activation.- Flush rules once (it’s better to store the state in option, instead of
activation
ordeactivation
, because on MultiSite they are
useless), or when you know that the rewrite rules need to be changed.
Don’t do it on any hook that will triggered on a routine basis.