Adding new field to all categories in worpdress

  • 0

/***adding malayalam title field to all product categories(product_cat) and taxonomies “writer”,”publisher”,***/
<?php
function add_new_cat_field() {
<div class=”form-field”>
<label for=”term_meta[mal_title]”><?php _e(‘Malayalam Title’, ‘text_domain’); ?></label>
<input type=”text” name=”term_meta[mal_title]” id=”term_meta[mal_title]”>
<p class=”description”><?php _e(‘Enter a malayalam title’, ‘text_domain’); ?></p>
</div>
<?php
}
add_action(‘product_cat_add_form_fields’, ‘add_new_cat_field’);
add_action(‘writer_add_form_fields’, ‘add_new_cat_field’);
add_action(‘publishers_add_form_fields’, ‘add_new_cat_field’);
//Product Cat Edit page
function edit_new_cat_field($term) {

//getting term ID
$term_id = $term->term_id;

// retrieve the existing value(s) for this meta field. This returns an array
$term_meta = get_option(“taxonomy_” . $term_id);
?>
<tr class=”form-field”>
<th scope=”row” valign=”top”><label for=”term_meta[mal_title]”><?php _e(‘Meta Title’, ‘text_domain’); ?></label></th>
<td>
<input type=”text” name=”term_meta[mal_title]” id=”term_meta[mal_title]” value=”<?php echo esc_attr($term_meta[‘mal_title’]) ? esc_attr($term_meta[‘mal_title’]) : ”; ?>”>
<p class=”description”><?php _e(‘Enter malayalam title’, ‘text_domain’); ?></p>
</td>
</tr>
<?php
}

add_action(‘product_cat_edit_form_fields’, ‘edit_new_cat_field’);
add_action(‘writer_edit_form_fields’, ‘edit_new_cat_field’);
add_action(‘publishers_edit_form_fields’, ‘edit_new_cat_field’);
// Save extra taxonomy fields callback function.
function save_new_cat_field($term_id) {
if (isset($_POST[‘term_meta’])) {
$term_meta = get_option(“taxonomy_” . $term_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_” . $term_id, $term_meta);
}
}

add_action(‘edited_product_cat’, ‘save_new_cat_field’);
add_action(‘create_product_cat’, ‘save_new_cat_field’);
add_action(‘edited_writer’, ‘save_new_cat_field’);
add_action(‘create_writer’, ‘save_new_cat_field’);
add_action(‘edited_publishers’, ‘save_new_cat_field’);
add_action(‘create_publishers’, ‘save_new_cat_field’);

/***adding malayalam title field to all product categories(product_cat) and taxonomies “writer”,”publisher”,***/ <?php function add_new_cat_field() { <div class=”form-field”> <label for=”term_meta[mal_title]”><?php _e(‘Malayalam Title’, ‘text_domain’); ?></label> <input type=”text” name=”term_meta[mal_title]” id=”term_meta[mal_title]”> <p class=”description”><?php _e(‘Enter a malayalam title’, ‘text_domain’); ?></p> </div> <?php } add_action(‘product_cat_add_form_fields’, ‘add_new_cat_field’); add_action(‘writer_add_form_fields’, ‘add_new_cat_field’); add_action(‘publishers_add_form_fields’, ‘add_new_cat_field’); //Product Cat Edit page function edit_new_cat_field($term) { //getting term ID $term_id…

/***adding malayalam title field to all product categories(product_cat) and taxonomies “writer”,”publisher”,***/ <?php function add_new_cat_field() { <div class=”form-field”> <label for=”term_meta[mal_title]”><?php _e(‘Malayalam Title’, ‘text_domain’); ?></label> <input type=”text” name=”term_meta[mal_title]” id=”term_meta[mal_title]”> <p class=”description”><?php _e(‘Enter a malayalam title’, ‘text_domain’); ?></p> </div> <?php } add_action(‘product_cat_add_form_fields’, ‘add_new_cat_field’); add_action(‘writer_add_form_fields’, ‘add_new_cat_field’); add_action(‘publishers_add_form_fields’, ‘add_new_cat_field’); //Product Cat Edit page function edit_new_cat_field($term) { //getting term ID $term_id…