1

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.

1
  • Can we see the function that saves your meta data please?
    – Jared
    Jan 24, 2012 at 14:12

1 Answer 1

1

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:

add_filter('wp_insert_post_empty_content', '__return_false');

I've successfully created a post with only meta fields with the code above.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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