Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
    
Can we see the function that saves your meta data please? –  Jared Jan 24 '12 at 14:12
add comment

1 Answer

up vote 1 down vote accepted

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.

share|improve this answer
    
Thanks just what I needed! –  drtanz Jan 24 '12 at 19:35
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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