1

Is there a reason when using the add_meta_box() callback, that when I do global $post I can't seem to access anything, or get the ID. I'm in WooCommerce, do I need to use global $product instead... if so why?

When I do add_meta_box( 'supplier_package_box', __( 'Supplier', 'supplier' ), 'populate_meta_box' );

In my callback:

function populate_meta_box(){
    global $post
    print_r($post);
    echo '</br>';

$post is always empty... for context I want to check if a post meta exists so I can populate an input box if necessary. :)

2

You should avoid using global variables where possible. For metaboxes you should use the $post variable that is passed to the callback function instead:

add_meta_box( 'supplier_package_box', __( 'Supplier', 'supplier' ), 'populate_meta_box' );

function populate_meta_box( $post ){
    print_r($post);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.