Benjamin Turner
Custom fields are arbitrary meta data that we can assign to a post.
This data is in the form of a key / value pair.
So for example, if we wanted to record the name of the book we are currently reading when we are writing a specific post, we might:
Alice in Wonderland
currently_reading
WordPress allows us to do this out of the box.
Note that WordPress uses 'Name' here instead of 'Key'
If that metabox isn't displayed, you might have to enable it by checking "Custom Fields" from the "Screen Options" button toward the top of the "edit post screen".
It's only text input.
Who really wants to hand enter something like location?
US Bancorp Tower
It doesn't show all of the custom fields for a post (i.e. things prefixed with an underscore).
There are a lot of plugins that work with custom fields
https://wordpress.org/search/custom+fields
Nothing out of the box.
You have to write the code describing the kinds of meta fields you want.
Hook into CMB2 with a custom function
add_action( 'cmb2_admin_init', 'register_metabox' );
function register_metabox() {
$prefix = 'yourprefix_demo_';
// Define Custom Fields
}
Create a new Metabox to attach our custom fields to
$cmb_demo = new_cmb2_box( array(
'id' => $prefix . 'metabox',
'title' => esc_html__( 'Test Metabox', 'cmb2' ),
'object_types' => array( 'page' ), // Post type
) );
Add field(s) to the previously created Metabox
$cmb_demo->add_field( array(
'name' => esc_html__( 'Test Text', 'cmb2' ),
'desc' => esc_html__( 'field description (optional)', 'cmb2' ),
'id' => $prefix . 'text',
'type' => 'text',
) );
Which gives us
There are lots of additional fields included with the default CMB2 plugin.
There are lots of ways: