fbpx

Registering default values for meta data

GET UP TO $500K IN BUSINESS FUNDING

With WordPress 5.5, the register_meta() functions ( including register_post_meta() ) now support registering default values. Previously it was only possible to register default values for the REST API schema like this:

register_meta( ‘post’, ‘greeting’, array( ‘single’ => true, ‘type’ => ‘string’, ‘show_in_rest’ => array( ‘schema’ => array( ‘type’ => ‘string’, ‘default’ => ‘hello’, ), ), ) );

However, this would only be applied to calls made from within the REST API – calls to get_post_meta() would not use this default value. Now it is possible to pass in a default value that will be applied to all calls to any of

BUILD A WEBSITE: RESOURCES

Pin It on Pinterest

Share This
Xiphos Web Marketing

FREE
VIEW