WordPress.org

Make WordPress Core

Opened 5 months ago

Closed 5 months ago

Last modified 5 months ago

#47576 closed defect (bug) (reported-upstream)

Duplicate Custom Fields are created in new post

Reported by: mhalamine Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Editor Keywords:
Focuses: Cc:
PR Number:

Description

Duplicate custom fields are created when publishing a post or saving it as draft

Steps to reproduce:
Create a New Post
Add a custom field "custom_field_1" with a value "custom_field_value_1"
Add a custom field "custom_field_2" with a value "custom_field_value_2"
Save Draft or Publish

...you will now see the "custom_field_1" field repeated twice (both with a value of "custom_field_value_1")

Another Case:
Create a New Post
Select a custom field from drop down set value to "custom_field_value_3"
save Draft or Publish
... you will now see that the selected field repeated twice with same value

Attachments (1)

Screen Shot 2019-06-20 at 2.23.38 PM.jpg (105.1 KB) - added by mhalamine 5 months ago.
Screenshot of result

Download all attachments as: .zip

Change History (5)

@mhalamine
5 months ago

Screenshot of result

#1 @goaroundagain
5 months ago

I think that's the desired behavior: https://wordpress.org/support/article/custom-fields/

"Keys can be used more than once per post. For example, if you were reading two different books (perhaps a technical book at work and a fiction at home), you could create a “reading” key and use it twice on the same post, once for each book."

If you use the php function add_post_meta you can set $unique = true: https://codex.wordpress.org/Function_Reference/add_post_meta

"Whether or not you want the key to stay unique. When set to true, the custom field will not be added if the given key already exists among custom fields of the specified post."

#2 @mhalamine
5 months ago

You are right about using the key twice but the issue is not here, the issue is that i created only one field but after i saved i got 2 identical entries for the same key.

Try the following:
Create a New Post
Add a custom field "custom_field_1" with a value "custom_field_value_1"
Save Draft or Publish
...you will now see the "custom_field_1" field repeated twice (both with a value of "custom_field_value_1")

#3 follow-up: @garrett-eclipse
5 months ago

  • Component changed from Options, Meta APIs to Editor
  • Keywords needs-patch removed
  • Milestone Awaiting Review deleted
  • Resolution set to reported-upstream
  • Status changed from new to closed
  • Version 5.2.2 deleted

Thanks for the report @mhalamine I was also able to reproduce this but only in the block editor (Gutenberg) and not the classic editor.

I found it's already been reported on the Gutenberg GitHub repo here;
https://github.com/WordPress/gutenberg/issues/11976

As such am closing this as reported-upstream where I made a reference to this ticket. If you have further information please supply it on that ticket as any fix will be worked on there first and then merged into core.

All the best

#4 in reply to: ↑ 3 @mhalamine
5 months ago

Replying to garrett-eclipse:

Thanks for the report @mhalamine I was also able to reproduce this but only in the block editor (Gutenberg) and not the classic editor.

I found it's already been reported on the Gutenberg GitHub repo here;
https://github.com/WordPress/gutenberg/issues/11976

As such am closing this as reported-upstream where I made a reference to this ticket. If you have further information please supply it on that ticket as any fix will be worked on there first and then merged into core.

All the best

@garrett-eclipse thanks for the effort. I will try to debug locally and see if i can come up with extra information that might help.

Note: See TracTickets for help on using tickets.