Hi I created a meta box on the post, page and project post types. The meta boxes save their data well on every post type. However I have a slight problem, when I create a new post and just enter a value in the meta box, then click ‘save draft’, the value in the meta box is not saved. On the pages and project post types the value would save.
The behaviour is that if I don’t enter anything in the title or the content of a new post, no metadata will be saved, and I also noticed that no permalink is generated, while for the other post types it is generated and the meta data is saved.
Is this standard WordPress behaviour or do I have some bug in my code? Functionally wise I don’t think it’s a big problem, because we will of course always be entering a title and content within the posts, but I’m curious about this behaviour and would like to know if it’s coming from my end or not. Thanks.
It’s default WordPress behavior. You cannot create, save or even trash “empty” posts (considering, for that last case, that you created one manually).
Luckily, there’s a filter that allows you to override it and insert / save posts without need for title or content; insert this into your
functions.php
:I’ve successfully created a post with only meta fields with the code above.