Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion custom_metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ function add_metadata_field( $field_slug, $object_types = array( 'post' ), $args
'select2' => false, // applies select2.js (work on select and multi select field types)
'min' => false, // a minimum value (for number field only)
'max' => false, // a maximum value (for number field only)
'step' => false, // a step value number intervals (for number field only)
'upload_modal_title' => __( 'Choose a file', 'custom-metadata' ), // upload modal title (for upload field only)
'upload_modal_button_text' => __( 'Select this file', 'custom-metadata' ), // upload modal button text (for upload field only)
'upload_clear_button_text' => __( 'Clear', 'custom-metadata' ), // upload clear field text (for upload field only)
Expand Down Expand Up @@ -1208,7 +1209,9 @@ function _display_metadata_field( $field_slug, $field, $object_type, $object_id,
case 'number' :
$min = ( ! empty( $field->min ) ) ? ' min="' . (int) $field->min . '"': '';
$max = ( ! empty( $field->max ) ) ? ' max="' . (int) $field->max . '"': '';
printf( '<input type="number" id="%s" name="%s" value="%s"%s%s%s%s/>', esc_attr( $field_slug ), esc_attr( $field_id ), esc_attr( $v ), $readonly_str, $placeholder_str, $min, $max );
$step = ( ! empty( $field->step ) ) ? ' step="' . (int) $field->step . '"': '';

printf( '<input type="number" id="%s" name="%s" value="%s"%s%s%s%s%s/>', esc_attr( $field_slug ), esc_attr( $field_id ), esc_attr( $v ), $readonly_str, $placeholder_str, $min, $max, $step );
break;
case 'textarea' :
printf( '<textarea id="%s" name="%s"%s%s>%s</textarea>', esc_attr( $field_slug ), esc_attr( $field_id ), $readonly_str, $placeholder_str, esc_textarea( $v ) );
Expand Down
15 changes: 13 additions & 2 deletions custom_metadata_examples.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,14 +264,14 @@ function x_init_custom_fields() {
'select2' => true,
) );

// adds a number field in the first group (with no min/max)
// adds a number field in the first group (with no min/max and step)
x_add_metadata_field( 'x_field_number', 'x_test', array(
'group' => 'x_metaBox1',
'field_type' => 'number',
'label' => 'Number field',
) );

// adds a number field in the first group (with min/max)
// adds a number field in the first group (with min/max and no step)
x_add_metadata_field( 'x_field_number_with_min_max', 'x_test', array(
'group' => 'x_metaBox1',
'field_type' => 'number',
Expand All @@ -281,6 +281,17 @@ function x_init_custom_fields() {
'label' => 'Number field (with min/max + cloneable)',
) );

// adds a number field in the first group (with min/max and step)
x_add_metadata_field( 'x_field_number_with_min_max_step', 'x_test', array(
'group' => 'x_metaBox1',
'field_type' => 'number',
'min' => '-3',
'max' => '25',
'step' => '5',
'multiple' => true,
'label' => 'Number field (with min/max and step + cloneable)',
) );

// adds an email field in the first group
x_add_metadata_field( 'x_field_email', 'x_test', array(
'group' => 'x_metaBox1',
Expand Down