0

I'm having troubles trying to do a hook when post published. I think that the problem is that my WP-Metaboxer plugin creates the meta after publishing post, and I cannot capture the value.

Here is an example:

function post_published_coins_update( $ID, $post ) {    
        $tipo = get_post_meta( $post->ID, 'tipo');

        $coins_value = $tipo;

        add_user_meta($post->post_author, 'coins', $coins_value);
    }
add_action('publish_post', 'post_published_coins_update',  10, 2);

I've created a metabox that create a post_meta called "tipo", but the hook doesn't access to it, is like if the hook starts before than the meta creates.

Any idea?

Thanks!

3

There is a dynamic hook right before any new metadata is added:

do_action( "add_{$meta_type}_meta", $object_id, $meta_key, $_meta_value );

It would be add_post_meta for posts accordingly.

Note that you might to tinker some to catch this precisely in the case of new post being created, for example hook into publish_post first, note the ID, and add to this hook from there.

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.