Your code works correctly on my installation. Is there any chance you previously moved a previous meta box with the same ID to the side column? Check your user meta keyed “meta-box-order_post”. If the ID is in this array, the box has been moved from its default position.
If not, your theme or one of your plugins must be manipulating how meta boxes work for some reason. If you want to identify the culprit, deactivate all plugins and switch to a default twenty* theme. Add your code temporarily to the theme’s functions.php file. You’ll find the meta box appears correctly. Restore your normal theme and again temporarily place your code in the functions.php file again. See if your box still appears correctly. Activate plugins one by one, testing after each. Once the box moves to the other column you’ve identified the culprit.
@bcworkz thanks and sorry for delay
You solved my problem!
Your code works correctly on my installation. Is there any chance you previously moved a previous meta box with the same ID to the side column? Check your user meta keyed “meta-box-order_post”. If the ID is in this array, the box has been moved from its default position.
Yes, its ID was (is!) in this array.
Finally, I’ve changed ID (from demo-meta-box to demo-meta-box2) and all works perfectly!
Just a question: why this behavior?
If I MUST use the first ID, can I clear the wordpress cache? Or what?
Thank you very much!! 🙂
-
This reply was modified 9 years, 6 months ago by
sandra11.
Delays are no problem, I’m here most days. There was also a holiday yesterday in the USA. And it’s you issue, not mine 🙂
Anytime a user moves a meta box from it’s default positioning, the new positioning is stored by ID in that user’s meta data. It pretty much persists there permanently, even when the meta box code is removed. A cache flush will not help, the data is written into the DB. There’s also no automatic cleanup mechanism. It’s up to the box’s developer to attempt such a clean up upon removal of their code. Even if such an attempt is made, it would depend on the user using the provided delete action. If they simply delete the code by FTP, there’s nothing a developer can do to cleanup after themselves.
If you come along and use the same ID, your box will “inherit” this old positioning even if this is the first time your box ever appeared to the user. Ideally, everyone would use a unique ID to avoid such issues. Attempting to reset any such old data upon activation could cause problems when a user temporarily deactivates/reactivates the theme/plugin for some reason. While it’s always a good idea to clean up after yourself upon removal (not the same as deactivation, each action fires a different action hook), it doesn’t always work and may not even be desirable. The user should typically be given the option to not do a cleanup upon removal.
Ok understood…
In the same way, on create new custom meta box, I think it would be useful not to use a “generic” ID too, because this could create problems in other plugins.
Thanks for clear explanation!!! 🙂
[Resolved]