php - WordPress: add check-boxes to custom taxonomy add/edit form -
i need add list of check-boxes custom taxonomy add/edit form. have code adding text field custom taxonomy form in plugin , works fine:
<?php function taxonomy_edit_meta_field($term) { $t_id = $term->term_id; $term_meta = get_option( "taxonomy_$t_id" ); ?> <tr class="form-field"> <th scope="row" valign="top"><label for="term_meta[custom_term_meta]"><?php _e( 'term:' ); ?></label></th> <td> <input type="text" name="term_meta[custom_term_meta]" id="term_meta[custom_term_meta]" value="<?php echo esc_attr( $term_meta['custom_term_meta'] ) ? esc_attr( $term_meta['custom_term_meta'] ) : ''; ?>"> </td> </tr> <?php } add_action( 'product_cat_edit_form_fields', 'taxonomy_edit_meta_field', 10, 2 ); function save_taxonomy_custom_meta( $term_id ) { if ( isset( $_post['term_meta'] ) ) { $t_id = $term_id; $term_meta = get_option( "taxonomy_$t_id" ); $cat_keys = array_keys( $_post['term_meta'] ); foreach ( $cat_keys $key ) { if ( isset ( $_post['term_meta'][$key] ) ) { $term_meta[$key] = $_post['term_meta'][$key]; } } update_option( "taxonomy_$t_id", $term_meta ); } } add_action( 'edited_product_cat', 'save_taxonomy_custom_meta', 10, 2 ); add_action( 'create_product_cat', 'save_taxonomy_custom_meta', 10, 2 );
how can add list of check-boxes in same way?
you need change name of hook.
add_action( 'edited_custom_tax', 'save_taxonomy_custom_meta', 10, 2 );
Comments
Post a Comment