Return meta values from Edit Product Category

Support MB Term Meta Return meta values from Edit Product Category

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #3863
    bodenburgcbodenburgc
    Participant

    Looking for some assistance in returning values from Woocommerce "Edit Product Category" page. Able to display fields with the "Edit Product Category" page, but I haven't figured out how to return the value. Here is my register code. Need help to return the value of the id.

    add_filter( 'rwmb_meta_boxes', 'bodie_register_meta_boxes' );
    function bodie_register_meta_boxes( $meta_boxes )
    {
    	$meta_boxes[] = array(
    		'title'      => 'Standard Fields',
    		'taxonomies' => 'product_cat',
    		'fields' => array(
    			array(
    				'name' => __( 'Dark Overlay?', 'bodie_theme' ),
    				'id'   => 'dark_overlay',
    				'type' => 'checkbox',
    			)
    		),
    	);
    	return $meta_boxes;
    }
    
    Failed
    // echo get_post_meta($post->ID, 'dark_overlay', true);
    // echo get_post_meta($term_id->ID, 'dark_overlay', true);
    #3865
    Anh TranAnh Tran
    Keymaster

    Hi,

    This is term meta and you should use get_term_meta instead of get_post_meta:

    echo get_post_meta($term_id->ID, 'dark_overlay', true);

    #3866
    Anh TranAnh Tran
    Keymaster

    Hi,

    This is term meta and you should use get_term_meta instead of get_post_meta:

    echo get_post_meta($term_id, 'dark_overlay', true);

    #3870
    bodenburgcbodenburgc
    Participant

    I am an idiot 🙂 THANKS

    #3871
    bodenburgcbodenburgc
    Participant

    For anyone else,
    Got it to work like this
    echo get_term_meta(get_queried_object()->term_id, 'dark_overlay', true);

    #3876
    Anh TranAnh Tran
    Keymaster

    I think it's better to use get_queried_object_id() 😉

Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘Return meta values from Edit Product Category’ is closed to new replies.