Why is `add_meta_box` not working?

I’m trying to add some meta fields to a WPSC product using the following code:

/**
 * data callback
 */
function abc_callback($object, $box)
{
    echo 'callback executed!';
}

/**
 * add custom fields
 */
function abc_load_post($post_id)
{
    add_meta_box('abc_post_id', 'abc', 'abc_callback', 'post', 'normal', 'default', array());
}
add_action('load-post.php', 'abc_load_post', 10, 2);
add_action('load-post-new.php', 'abc_load_post', 10, 2);

The abc_load_post function gets called fine but nothing actually appears on the product editing page (i.e. /wp-admin/post.php)

Read More

Can someone explain what I’m doing wrong?

Related posts

Leave a Reply

2 comments

  1. I can see 2 problems with your code. You seem to want that meta box to appear on product pages, but you actually add it to the post type and not the product post type. The other problem is the hook you attach your function to. Try this:

    add_action( 'add_meta_boxes_{post_type}', 'abc_load_post' );
    

    Substitute {post_type} with whatever post type you actually want to target, e.g. product, post or page. The fourth argument for add_meta_box() is the post type, btw, which you have set to ‘post’.