ajacobs
ajacobs

Reputation: 11

What action hook would I use to update post meta when viewing a post in Wordpress admin?

Example URL: mywebsite.com/wp-admin/post.php?post=1234&action=edit

I have found hooks that fire when a post is created/edited/status changed, but nothing that works for just viewing a post.

I need to check some meta data and update it before the post is displayed to the user

I have tried several hooks already but none let me edit post meta at the correct time (when viewing a post)

Solution: Adding this to admin_init allowed me to update post meta for a given post after the post data was loaded

if (isset($_GET['post']) && (isset($_GET['action']) && $_GET['action'] == 'edit'))
{
   $post = get_post($_GET['post']);

   if ($post->post_type == 'program')
   {
      // do stuff
   }
}

Upvotes: 0

Views: 448

Answers (2)

Coopero
Coopero

Reputation: 296

Not sure if there's a hook so you could either add one manually or use something like this

global $pagenow;
if (is_admin() && $pagenow == 'post.php') {

    // editing a post

}

Upvotes: 0

zia ud din
zia ud din

Reputation: 1

save_post hook in your case what you are trying to do show your code

Upvotes: 0

Related Questions