Skip to content

Instantly share code, notes, and snippets.

@cristianstan
Forked from jtsternberg/cmb2-number-field.php
Created September 27, 2018 11:17
Show Gist options
  • Save cristianstan/7afc7d69ace0b047fc12116161af90c3 to your computer and use it in GitHub Desktop.
Save cristianstan/7afc7d69ace0b047fc12116161af90c3 to your computer and use it in GitHub Desktop.
CMB2 Number Field
<?php
$cmb->add_field( array(
'name' => __( 'Postive numbers', 'theme-domain' ),
'desc' => __( 'Numbers only', 'msft-newscenter' ),
'id' => $prefix . 'number',
'type' => 'text',
'attributes' => array(
'type' => 'number',
'pattern' => '\d*',
),
'sanitization_cb' => 'absint',
'escape_cb' => 'absint',
) );
$cmb->add_field( array(
'name' => __( 'Numbers', 'theme-domain' ),
'desc' => __( 'Numbers only', 'msft-newscenter' ),
'id' => $prefix . 'number',
'type' => 'text',
'attributes' => array(
'type' => 'number',
'pattern' => '\d*',
),
'sanitization_cb' => 'intval',
'escape_cb' => 'intval',
) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment