0

I'm looking to use the bitly api to generate a shortened url for all posts and pages.

My plan is to generate this when the post is saved, then save the shortened to the post when the API call is answered. But I'm worried that if I use the wrong hook I'll end up in an infinite loop of listening for the update hook, then triggering the update hook.

So how can I avoid this, or is there a hook I can use that will trigger when a post is updated but wouldn't trigger when I add meta data to a post

1 Answer 1

0

Use the hook 'save_post' that pass 1 arguments: $post_id. Update_post_meta won't trigger save_post.

add_action('save_post', 'custom_add_meta', 10, 1);

function custom_add_meta($post_id){
    update_post_meta($post_id, 'meta_key', $value);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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