[wp-trac] [WordPress Trac] #47576: Duplicate Custom Fields are created in new post

WordPress Trac noreply at wordpress.org
Thu Jun 20 13:27:29 UTC 2019


#47576: Duplicate Custom Fields are created in new post
--------------------------------+------------------------------
 Reporter:  mhalamine           |       Owner:  (none)
     Type:  defect (bug)        |      Status:  new
 Priority:  normal              |   Milestone:  Awaiting Review
Component:  Options, Meta APIs  |     Version:  5.2.2
 Severity:  normal              |  Resolution:
 Keywords:  needs-patch         |     Focuses:
--------------------------------+------------------------------

Comment (by goaroundagain):

 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."

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/47576#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list