Skip to content

Instantly share code, notes, and snippets.

@alokstha1
Created July 7, 2016 16:31
Show Gist options
  • Save alokstha1/9108ac65459ec7aa8588802a4c0d3731 to your computer and use it in GitHub Desktop.
Save alokstha1/9108ac65459ec7aa8588802a4c0d3731 to your computer and use it in GitHub Desktop.
Adding Extra Field in Term Field both on Add and Edit Form WordPress
add_filter( 'pa_color_add_form_fields', array( $this, 'pa_attr_taxonomy_columns' ) );
add_filter( 'pa_color_edit_form_fields', array( $this, 'edit_pa_attr_taxonomy_column' ), 10 );
add_action( 'created_pa_color', array( $this, 'pa_attr_save_taxonomy_fields' ), 10, 2 );
add_action( 'edit_pa_color', array( $this, 'pa_attr_save_taxonomy_fields' ), 10, 2 );
/**
* Add Fields
*
*/
public function pa_attr_taxonomy_columns() {
$terms = get_terms( $taxonomy, array(
'hide_empty' => false,
'parent' => 0
) );
if ( !empty( $terms ) ) {
?>
<div class="form-field term-related-terms-wrap">
<label for="related_">Related Terms</label>
<select name="related[]" id="related_<?php echo $taxonomy; ?>" multiple="multiple" class="postform">
<option value="">None</option>
<?php
foreach ($terms as $term_value) { ?>
<option value="<?php echo $term_value->term_id; ?>"><?php echo $term_value->name; ?></option>
<?php
}
?>
</select>
</div>
<?php
}
}
public function edit_pa_attr_taxonomy_column( $term ) {
$terms = get_terms( $taxonomy, array(
'hide_empty' => false,
'parent' => 0
) );
if ( !empty( $terms ) ) {
?>
<tr class="form-field">
<th scope="row" valign="top"><label>Related Term</label></th>
<td>
<select name="related[]" multiple="multiple">
<option value="">None</option>
<?php
foreach ($terms as $term_value) {
$related_color_swatches = cc_get_term_meta( $term_value->term_id, 'related', true );
if ( empty( $related_color_swatches ) ) {
$related_color_swatches = array();
}
?>
<option value="<?php echo $term_value->term_id; ?>" <?php if ( in_array( $term->term_id, $related_color_swatches ) ) {
echo 'selected="selected"';
} ?> >
<?php echo $term_value->name; ?>
</option>
<?php
}
?>
</select>
</td>
</tr>
<?php
}
}
/*
* Update terms meta
*
*/
public function pa_attr_save_taxonomy_fields( $term_id, $tt_id = '' ) {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment