cmb2_get_field
Get a CMB2 field object.
Description
(CMB2_Field|null) cmb2_get_field( (array) $meta_box, (array) $field_id, (int) $object_id = 0, (string) $object_type = '' );
Returns (CMB2_Field|null)
CMB2_Field object unless metabox config cannot be found
Parameters (4)
- 0. $meta_box (array)
- Metabox ID or Metabox config array
- 1. $field_id (array)
- Field ID or all field arguments
- 2. $object_id — Optional. (int)
- The object id.
- 3. $object_type — Optional. (string) =>
''
- Type of object being saved. (e.g., post, user, comment, or options-page). Defaults to metabox object type.
Usage
if ( !function_exists( 'cmb2_get_field' ) ) { require_once ABSPATH . PLUGINDIR . 'maps-builder/includes/libraries/metabox/includes/helper-functions.php'; } // Metabox ID or Metabox config array $meta_box = array(); // Field ID or all field arguments $field_id = array(); // The object id. $object_id = -1; // Type of object being saved. (e.g., post, user, comment, or options-page). // Defaults to metabox object type. $object_type = ''; // NOTICE! Understand what this does before running. $result = cmb2_get_field($meta_box, $field_id, $object_id, $object_type);
Defined (2)
The function is defined in the following location(s).
- /includes/libraries/metabox/includes/helper-functions.php
- function cmb2_get_field( $meta_box, $field_id, $object_id = 0, $object_type = '' ) {
- $object_id = $object_id ? $object_id : get_the_ID();
- $cmb = $meta_box instanceof CMB2 ? $meta_box : cmb2_get_metabox( $meta_box, $object_id );
- if ( ! $cmb ) {
- return;
- }
- $cmb->object_type( $object_type ? $object_type : $cmb->mb_object_type() );
- return $cmb->get_field( $field_id );
- }
- /vendor/wordimpress/maps-builder-core/includes/libraries/metabox/includes/helper-functions.php
- function cmb2_get_field( $meta_box, $field_id, $object_id = 0, $object_type = '' ) {
- $object_id = $object_id ? $object_id : get_the_ID();
- $cmb = $meta_box instanceof CMB2 ? $meta_box : cmb2_get_metabox( $meta_box, $object_id );
- if ( ! $cmb ) {
- return;
- }
- $cmb->object_type( $object_type ? $object_type : $cmb->mb_object_type() );
- return $cmb->get_field( $field_id );
- }