Make WordPress Core

Opened 13 years ago

Closed 9 years ago

#18979 closed enhancement (fixed)

Add $post_type parameter and a filter to meta_form()

Reported by: takayukister's profile takayukister Owned by:
Milestone: 4.4 Priority: normal
Severity: normal Version:
Component: Administration Keywords:
Focuses: ui Cc:


In the current version, meta_form(), the function which outputs Custom Fields form used in Edit Post pages, shows all meta keys you have used regardless of post type. Sometimes this gives users unwanted options.

I'd like to suggest adding $post_type parameter to meta_form() to show only meta keys you have used in the same post type. In addition, it would be better if there were a filter for the meta keys.

Attachments (1)

meta_form.diff (1.7 KB) - added by takayukister 13 years ago.
a patch for meta_form()

Download all attachments as: .zip

Change History (11)

13 years ago

a patch for meta_form()

#1 @nacin
13 years ago

I would rather the solution just be that a developer disables the Custom Fields box and creates their own meta box. Any improvements here seem like they're a waste of energy (and CPU).

#2 @michelwppi
12 years ago

  • Cc contact@… added

Just a short contribution to improve - old - meta_form() function according filtering and protecting rules of meta_key and custom post type:

In current post_custom_meta_box (displaying custom form fields), list_meta is filtered via is_protected_meta function (and his own available filter 'is_protected_meta'). But it is impossible to filter the content of the popup list populated by $key built by meta_form().

With 'is_protected_meta' filter it is possible to subselect metas according context. To subselect popup menu , I suggest a very simple filter just before

<td id="newmetaleft" class="left">
<?php if ($keys){
 <td id="newmetaleft" class="left">
$keys = apply_filters( 'post_meta_key_subselect', $keys, $limit);
if ($keys){

Inside the filter, it will be easy to re-query keys (like described above by takayukister) or to subselect and sort the popup list according context an rules (post_type, and more...) without rebuilding a whole custom field metabox UI. It is also a simple way to fixe contamination of keys used buy one post type in another.

This very simple improvement is in concordance with the available filter 'is_protected_meta' where it is possible to not only subselect key with prefix '_' but with another rules.

Hope that help to review.

Version 1, edited 12 years ago by michelwppi (previous) (next) (diff)

#3 @chriscct7
10 years ago

  • Keywords needs-refresh added

#4 @chriscct7
9 years ago

  • Component changed from Editor to Administration
  • Focuses performance added
  • Keywords needs-refresh removed
  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #24498.

#5 @kitchin
9 years ago

  • Focuses ui added; performance removed
  • Resolution duplicate deleted
  • Status changed from closed to reopened

The duplicate that was fixed, #24498, did not address this bug. Also, adding UI focus, since the bug is for a behavior improvement, not performance.

Last edited 9 years ago by SergeyBiryukov (previous) (diff)

#6 @SergeyBiryukov
9 years ago

  • Milestone set to Awaiting Review

#7 @SergeyBiryukov
9 years ago

[35717] introduced the postmeta_form_keys filter.

#8 @helen
9 years ago

I don't really want to encourage continued use of this meta box by making default UI improvements. Can this be called fixed with [35717]?

#9 @helen
9 years ago

In 35730:

Pass the $post object as context to postmeta_form_keys.

see #33885, #18979.

#10 @SergeyBiryukov
9 years ago

  • Milestone changed from Awaiting Review to 4.4
  • Resolution set to fixed
  • Status changed from reopened to closed
Note: See TracTickets for help on using tickets.