Opened 15 years ago
Closed 15 years ago
#13401 closed defect (bug) (fixed)
Add custom field to new post doesn't create draft
Reported by: | duck_ | Owned by: | |
---|---|---|---|
Milestone: | 3.0 | Priority: | high |
Severity: | blocker | Version: | 3.0 |
Component: | General | Keywords: | has-patch |
Focuses: | Cc: |
Description
The add-meta
case in admin-ajax.php no longer creates a draft post if custom field data is added to a new post. This is because it is checking for a post ID < 0 instead of checking for auto-draft status.
Steps:
- Add new post
- Add custom field - without letting autosave occur, so don't enter title etc.
- Leave page without saving
Expected: 2.9 behaviour was to create a draft with custom fields and draft title
Actual: New post stays as auto-draft so isn't displayed in list of posts to edit
Attachments (2)
Change History (15)
#3
@
15 years ago
- Keywords has-patch added; needs-patch removed
I added a patch, if you add a meta and post status is auto-draft then create a draft.
#4
@
15 years ago
- Keywords needs-patch added; has-patch removed
edit_post() also use add_meta() => the meta gets added twice.
#5
@
15 years ago
- Keywords has-patch added; needs-patch removed
13401.2.patch: To prevent that edit_post() add the meta we can clear $_POST. Then fill it with the needed data and after edit_post() we can restore the original $_POST.
#7
@
15 years ago
You can pass post data to edit_post() instead of having it rely on the _POST super global. I think that will save some of the POST juggling the patch does.
#8
@
15 years ago
ryan, what do you mean? If i add the original $_POST to edit_post() it will add the meta to and I can't get the meta id, because it returns only the post id. Because of that I make a backup, send to edit_post() only title,status,post_id,post_type and then restore the original $_POST to add the meta (and then I have the meta id).
#9
follow-up:
↓ 10
@
15 years ago
$post_data = array(); $post_data['post_ID'] = $pid; ... $pid = edit_post($post_data);
That way _POST can be left untouched.
#10
in reply to:
↑ 9
@
15 years ago
Replying to ryan:
$post_data = array(); $post_data['post_ID'] = $pid; ... $pid = edit_post($post_data);That way _POST can be left untouched.
Unfortunately the problem with that is the issue of duplicate fields arises again. add_meta(), which is called as part of edit_post(), doesn't look at the array passed to edit_post() it only uses the $_POST super global.
#11
@
15 years ago
Ah, that is lame. add_meta() should accept post_data then, just like edit_post() does. Getting rid of the extra add_meta() would be nice too.
#13
@
15 years ago
- Resolution set to fixed
- Status changed from new to closed
Let's not complicate the matter and go with the current patch. If anyone feels like cleaning up add_meta(), re-open and go ahead.
I totally overlooked ocean90's comment explaining the POST juggling. Sorry for the confusion.
Slightly related: #13400