Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Add this into your functions.php file for the form.
- // This part populates the form with the data already in the database.
- // You should edit everything that is IN_ALL_CAPS.
- $YOUR_TERMS_VAR = get_the_terms( $post->ID, 'YOUR_TAXONOMY' );
- if ( $YOUR_TERMS_VAR && ! is_wp_error( $YOUR_TERMS_VAR ) ) :
- $SELECTED_ITEMS = array();
- foreach ( $YOUR_TERMS_VAR as $term ) {
- //use "slug" instead of "id" or "value"
- $SELECTED_ITEMS[] = $term->slug;
- }
- $teachers = join( ", ", $SELECTED_ITEMS );
- endif;
- $current_student_data['SELECTED_ITEMS'] = $teachers;
- // you may also use "gform_after_submission_##" for a specific form.
- add_action( 'gform_after_submission', 'gf_edit_student', 10, 2 );
- function gf_edit_student( $entry, $form ) {
- global $post;
- global $wpdb;
- global $wp_query;
- $postID = $wp_query->post->ID;
- // YOUR_TERMS_VAR should match what is above.
- // This part saves the new data to the database.
- // the "." [dot] after the 30 (which should be your ID of your checkbox field) stays.
- $YOUR_TERMS_VAR = array();
- foreach($entry as $field=>$slug){
- if (substr($field, 0, 3) == '30.' ) { //30. = the id of your checkboxes
- $YOUR_TERMS_VAR[] = $slug;
- }
- }
- // YOUR_TERMS_VAR should match what is above.
- // Edit "YOUR_TAXONOMY" to be your taxonomy name.
- wp_set_object_terms($postID, $YOUR_TERMS_VAR, 'YOUR_TAXONOMY');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement