Skip to content

Custom Fields API

Register your own metadata fields on references. Registered fields integrate with the reference admin UI, the REST API (optional), and export.

Call ABT_Custom_Fields::register_field() with a field ID and arguments, typically on init:

add_action( 'init', function () {
ABT_Custom_Fields::register_field( 'custom_rating', array(
'label' => 'Rating',
'type' => 'number',
'description' => 'Rate this reference 1-5',
'min' => 1,
'max' => 5,
'show_in_rest' => true,
) );
} );
Key Default Description
label (from field ID) Field label in the admin
type text Field type: text, number, select, and other supported types
description (empty) Help text shown under the field
default (empty) Default value
options [] Choices for select / radio field types
sanitize (by type) Sanitize callback; defaults to one appropriate for the type
show_in_rest false Expose the field in the REST API
show_in_admin true Show the field on the reference edit screen
show_in_export true Include the field when exporting

If you omit label, it is generated from the field ID. If you omit sanitize, a default callback is chosen based on type. Unknown types fall back to text.

ABT_Custom_Fields::unregister_field( 'custom_rating' );