Using ‘before’ in field call, deletes input field but not label?
-
I am using the callback ‘before’ on specific fields. I find the field in question, check my category of the record I am going to display and choose to hide or display that field according to the post category assignment.
case 'select_breed': $AllLists = mmd_lists_GetHorseBreeds(); $cmb->add_group_field( $group_field_id, array( 'name' => $FieldLabel, 'id' => $FieldId, 'type' => 'select', 'desc' => $FieldInstruction, 'on_front' => false, 'sanitization_cb' => false, 'escape_cb' => false, 'attributes' => $Attributes, 'options' => $AllLists, 'before' => 'mmdlist_add_js_for_check_display_option', //'after_field' => 'mmdlist_add_js_for_check_display_option', ) ); break;
IF, I assign the type in this field to ‘hidden’ directly, both the label and the input field properly disappear from view. BUT, if I use the call back and do the following code, only the input field disappears.
What am I missing?
function mmdlist_add_js_for_check_display_option($field_args, $field) { $post = get_post(); $ListId = $post->ID; $FieldName = $field->args['_id']; $input_fields = mmd_lists_GetTemplateFields(0, 0); for($i=0; $i<sizeof($input_fields); $i++) { $Field = $input_fields[$i]; $FieldId = $Field['id']; $RecordCat = $Field['cat']; if( $FieldId == $FieldName) { break; } } $ListingCatagory = mmd_list_readDBSettings("LISTING_CATAGORY"); $HorseCatagory = mmd_list_readDBSettings("SALE_HORSE_CATAGORY"); $PostCatagoryList = get_the_terms( $ListId, 'mmdlist_cat' ); foreach($PostCatagoryList as $Cat) { $PostCatagory = $Cat->name; if($PostCatagory == $ListingCatagory) { if( strcmp($RecordCat, "A") == 0 || strcmp($RecordCat, "L")==0) return; $field->args['type'] = 'hidden'; // works } else if($PostCatagory == $HorseCatagory) { if( strcmp($RecordCat, 'A') == 0 || strcmp($RecordCat, 'H')==0) return; $field->args['type'] = 'hidden'; // works } }
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Using ‘before’ in field call, deletes input field but not label?’ is closed to new replies.