How can I get my custom term field value? No plugins(only wc)
-
I’ve created the ‘color field’ for pa_color taxonomy terms, by native ways, but how can I get their values to the place I need?
$term->themename_pa_color doesn’t work.
It works with name and description default fields, like $term->name or $term->description, but not with my field.
That’s how I created it, it correctly saves values.add_action( 'pa_color_add_form_fields', 'themename_pa_color_add_term_fields' ); function themename_pa_color_add_term_fields( $taxonomy ) { ?> <div class="form-field"> <label for="themename_pa_color">PA Color</label> <input type="color" name="themename_pa_color" id="themename_pa_color" class="wpColorChoose" /> <p>Field description may go here.</p> </div>; <?php } add_action( 'pa_color_edit_form_fields', 'themename_pa_color_edit_term_fields', 10, 2 ); function themename_pa_color_edit_term_fields( $term, $taxonomy ) { $value = get_term_meta( $term->term_id, 'themename_pa_color', true ); echo '<tr class="form-field"> <th> <label for="themename_pa_color">PA Color</label> </th> <td> <input name="themename_pa_color" id="themename_pa_color" type="color" class="wpColorChoose" value="' . esc_attr( $value ) .'" /> <p class="description">Field description may go here.</p> </td> </tr>'; } add_action( 'created_pa_color', 'themename_pa_color_save_term_fields' ); add_action( 'edited_pa_color', 'themename_pa_color_save_term_fields' ); function themename_pa_color_save_term_fields( $term_id ) { update_term_meta( $term_id, 'themename_pa_color', sanitize_text_field( $_POST[ 'themename_pa_color' ] ) ); }
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘How can I get my custom term field value? No plugins(only wc)’ is closed to new replies.