Post meta not saving in save_post function
-
Hey thanks ahead of time, here’s my problem.
Every time a post is updated i need to dynamically update or create a redirect for this post. I have the Quick Page/Post Redirect plugin installed which stores a post’s redirect as 3 postmeta fields:
_pprredirect_url,
_pprredirect_type
_pprredirect_activeI thought this would be a simple task and below is the code i thought would do the trick:
function post_redirect_create( $post_id ) { global $wpdb; //verify post is not a revision $file = get_field('file', $_POST['post_ID']); update_post_meta($_POST['post_ID'], _pprredirect_url, $file); update_post_meta($_POST['post_ID'], _pprredirect_type, "301"); update_post_meta($_POST['post_ID'], _pprredirect_active, "1"); } add_action( 'save_post', 'post_redirect_create' );
Unfortunately this doesn’t work. Nothing actually updates. I’ve verified that the correct data is getting to the
update_post_meta
function calls, by placing dumps and exit()’s. But the confusing part is if i add anexit()
call at the very end, then the redirect gets updated in the database correctly. There must be something after this call that’s either reverting what my function is doing, or there’s a race condition of some kind and my code never executes.Thanks again ahead of time. I’ve been wrestling with this problem all day and would love some help with this.
- The topic ‘Post meta not saving in save_post function’ is closed to new replies.