Created
July 8, 2015 23:53
-
-
Save codiller/dc4f16dd913b38c5ebb0 to your computer and use it in GitHub Desktop.
2 Text_Money fields in a custom field type not working
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'cmb2_render_rental_fees', 'cmb2_render_rental_fees_callback', 10, 5 ); | |
function cmb2_render_rental_fees_callback( $field, $value, $object_id, $object_type, $field_type_object ) { | |
$prefix = '_tlc_'; | |
$value = wp_parse_args( $value, array( | |
'rental-rent' => '', | |
'rental-deposit' => '', | |
) ); ?> | |
<div> | |
<p> | |
<label for="<?php echo $field_type_object->_id( $prefix . 'rental_rent' ); ?>"><?php echo esc_html( $field_type_object->_text( 'rental_rent_text', 'Rent' ) ); ?></label> | |
</p> | |
<?php echo $field_type_object->text_money( array( | |
'name' => $field_type_object->_name( '[rental-rent]' ), | |
'id' => $field_type_object->_id( $prefix . 'rental_rent' ), | |
'value' => $value['rental-rent'], | |
) ); ?> | |
</div> | |
<div> | |
<p> | |
<label for="<?php echo $field_type_object->_id( $prefix . 'rental_deposit' ); ?>"><?php echo esc_html( $field_type_object->_text( 'rental_deposit_text', 'Deposit' ) ); ?></label> | |
</p> | |
<?php echo $field_type_object->text_money( array( | |
'name' => $field_type_object->_name( '[rental-deposit]' ), | |
'id' => $field_type_object->_id( $prefix . 'rental_deposit' ), | |
'value' => $value['rental-deposit'], | |
) ); ?> | |
</div> | |
<?php } | |
add_action( 'cmb2_init', 'tlc_cmb_metaboxes_rentals' ); | |
function tlc_cmb_metaboxes_rentals() { | |
// Define a prefix | |
$prefix = '_tlc_'; | |
$tlc_cmb = new_cmb2_box( array( | |
'id' => $prefix . 'rental_information', | |
'title' => __( 'Rental Information', 'tlc' ), | |
'object_types' => array( 'tlc_rentals', ), // Post type | |
'priority' => 'high', | |
) ); | |
$tlc_cmb->add_field( array( | |
'name' => __( 'Rental Fees', 'tlc' ), | |
'id' => $prefix . 'rental_fees', | |
'type' => 'rental_fees', | |
) ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment