Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function pippin_taxonomy_add_new_meta_field() {
- // this will add the custom meta field to the add new term page
- ?>
- <div class="form-field">
- <label for="term_meta[custom_term_meta]"><?php _e( 'Select Users to Include', 'pippin' ); ?></label>
- <?php $authors = get_users();
- foreach($authors as $author) { ?>
- <input style="width:auto;" type="checkbox" name="term_meta[<?php echo $author->ID; ?>]" id="term_meta" value="<?php echo $author->ID; ?>">
- <?php echo $author->user_nicename; ?><br />
- <?php } ?>
- </div>
- <?php
- }
- add_action( 'category_add_form_fields', 'pippin_taxonomy_add_new_meta_field', 10, 2 );
- function pippin_taxonomy_edit_meta_field($term) {
- // put the term ID into a variable
- $t_id = $term->term_id;
- // retrieve the existing value(s) for this meta field. This returns an array
- $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( 'Select Users to Include', 'pippin' ); ?></label></th>
- <td>
- <?php $authors = get_users();
- foreach($authors as $author) {
- $user_id = $author->ID;
- if(in_array($user_id, $term_meta)) { ?>
- <input type="hidden" name="term_meta[<?php echo $author->ID; ?>]" value="">
- <input style="width:auto;" type="checkbox" name="term_meta[<?php echo $author->ID; ?>]" id="term_meta" value="<?php echo $author->ID; ?>" checked="checked">
- <?php echo $author->user_nicename; ?><br />
- <?php } else { ?>
- <input style="width:auto;" type="checkbox" name="term_meta[<?php echo $author->ID; ?>]" id="term_meta" value="<?php echo $author->ID; ?>">
- <?php echo $author->user_nicename; ?><br />
- <?php }
- } ?>
- </td>
- </tr>
- <?php
- }
- add_action( 'category_edit_form_fields', 'pippin_taxonomy_edit_meta_field', 10, 2 );
- function save_taxonomy_custom_meta( $term_id ) {
- $t_id = $term_id;
- $term_meta = get_option( "taxonomy_$t_id" );
- $cat_keys = array_keys( $_POST['term_meta'] );
- foreach ( $cat_keys as $key ) {
- if ( isset ( $_POST['term_meta'][$key] ) ) {
- $term_meta[$key] = $_POST['term_meta'][$key];
- }
- // Save the option array.
- update_option( "taxonomy_$t_id", $term_meta );
- }
- }
- add_action( 'edited_category', 'save_taxonomy_custom_meta', 10, 2 );
- add_action( 'create_category', 'save_taxonomy_custom_meta', 10, 2 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement