Exciting News! Flipper Code is now WePlugins! Same commitment to excellence, brand new identity.

How to use postmeta_form_keys filter in WordPress

Sandeep Kumar Mishra
Sandeep Kumar Mishra
July 2, 2023
5 minutes read

postmeta_form_keys filter

Filters values for the meta key dropdown in the Custom Fields meta box.

apply_filters( 'postmeta_form_keys', array|null $keys, WP_Post $post )

Description

This is filter hook , its filter values for the meta key dropdown in the Custom Fields meta box..
Returning a non-null value will effectively short-circuit and avoid a potentially expensive query against postmeta.
Its consists of two parameters, one is $keys, second is $post object.
Its used by meta_form() which print the form in the Custom Fields meta box.

Parameters

  • $keys : (array|null) Pre-defined meta keys to be used in place of a postmeta query. Default null.
  • $post : (WP_Post) The current post object.

Live Example

To run the hook, copy the example below.

apply_filters( 'postmeta_form_keys', array|null $keys, WP_Post $post )

The following example is for adding a hook callback.

add_filter('postmeta_form_keys','meta_form_keys');

function meta_form_keys($keys, $post ) {
   
    return $keys;
}

To remove a hook callback, use the example below.

// remove the filter 
add_filter( 'postmeta_form_keys', 'meta_form_keys', 10, 1 ); 
Sandeep Kumar Mishra

Sandeep Kumar Mishra

Sandeep Kumar Mishra writes about WordPress and Artificial Intelligence, offering tips and guides to help you master your website and stay updated with the latest tech trends.

Explore the latest in WordPress

Trying to stay on top of it all? Get the best tools, resources and inspiration sent to your inbox every Wednesday.