Add a custom meta box to the new/edit category pages

How to add a custom meta box to the new/edit category pages

 The meta data is saved to the array term_meta[], which can handle further fields in the future. To create a meta field or custom field in product category edit page wordpress provide a hook…

add_action( 'product_cat_edit_form_fields', 'wpm_product_cat_edit_details_meta' );

function wpm_product_cat_edit_details_meta( $term ) {
$product_cat_details = get_term_meta( $term->term_id, 'details', true );
if ( ! $product_cat_details ) {
$product_cat_details = '';
$settings = array( 'textarea_name','wpm-product-cat-details' );
//html goes here



Now in your edit category page meta box appears. See screenshot….

Now we need to save this meta field in database. WordPress provide two hooks to save meta field in database.
By using this code you can create any type of fields.


add_action( 'create_product_cat', 'wpm_product_cat_details_meta_save' );
add_action( 'edit_product_cat', 'wpm_product_cat_details_meta_save' );

function wpm_product_cat_details_meta_save( $term_id ) {
if ( ! isset( $_POST['wpm_product_cat_details_nonce'] ) || ! wp_verify_nonce( $_POST['wpm_product_cat_details_nonce'], basename( __FILE__ ) ) ) {
//echo $_POST['read_more'];
update_term_meta($term_id,'read_more', $_POST['read_more']);

Post Created 49

Leave a Reply

Related Posts

Begin typing your search above and press enter to search. Press ESC to cancel.

Back To Top