diff --git a/custom_metadata.php b/custom_metadata.php index d37c9d3..4130412 100644 --- a/custom_metadata.php +++ b/custom_metadata.php @@ -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) @@ -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( '', 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( '', esc_attr( $field_slug ), esc_attr( $field_id ), esc_attr( $v ), $readonly_str, $placeholder_str, $min, $max, $step ); break; case 'textarea' : printf( '', esc_attr( $field_slug ), esc_attr( $field_id ), $readonly_str, $placeholder_str, esc_textarea( $v ) ); diff --git a/custom_metadata_examples.php b/custom_metadata_examples.php index ff501da..915f8f2 100644 --- a/custom_metadata_examples.php +++ b/custom_metadata_examples.php @@ -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', @@ -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',