Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save cristianstan/9cec1e17fe4cc2174a481ccb21ce66ba to your computer and use it in GitHub Desktop.
Save cristianstan/9cec1e17fe4cc2174a481ccb21ce66ba to your computer and use it in GitHub Desktop.
CM2 default post id with suffix or prefix
<?php
// CMB2 with Prefix
function prefix_default_offer_id_by_offer_id( $field_args, $field ) {
return 'prefix_'. $field->object_id;
}
$cmb->add_field( array(
'name' => esc_html__( 'Nr. Oferta', 'cmb2' ),
'id' => 'woopog_offer_id',
'type' => 'text',
// 'default' => '',
'default_cb' => 'prefix_default_offer_id_by_offer_id',
) );
// CMB2 with Suffix
function suffix_default_offer_id_by_offer_id( $field_args, $field ) {
return $field->object_id.'_suffix';
}
$cmb->add_field( array(
'name' => esc_html__( 'Nr. Oferta', 'cmb2' ),
'id' => 'woopog_offer_id',
'type' => 'text',
// 'default' => '',
'default_cb' => 'suffix_default_offer_id_by_offer_id',
) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment