When a user publishes or updates a post I want to get a post meta value from that post itself. Then I want to use update_option() to pass that value into the get_option() name.

I've been trying multiple things and I know this works, but it seems the issue I am having is this happening during the save_post action? If I remove the action everything works fine. I've tried other action points but still nothing has worked.

I'm kind of guessing that at the time these actions run is before the post_meta data is saved so I can get that value in time to pass to the update_option(); Is this true?

How should I go about this? - Thanks.

  • Or the issue is detecting the id of the post itself so I can get the post meta from the post being created after it's saved, then passing that into update_option. ? – Fearless Mode Mar 29 '17 at 18:59
  • When the user publishes the post, will the meta value you want be submitted? If so, using the save_post hook, the meta value will be available in the $_POST variable and you can use update_option to save it to the options table. – AncientRo Mar 30 '17 at 6:38
  • @AncientRo thanks. Yes and this makes sense. I've looked around for about an hour because I'm not familiar with the global $_POST. Do you know how I can inspect this on the save_post action or how to access my saved array fields submitted? I tried just using $_POST['my-field'] but nothing happened. But I don't know what the data in there looks like. – Fearless Mode Mar 30 '17 at 18:03
  • Can you give a bit more context, please? What post type are you using, a custom post type or a native one? How did you add the meta post fields? If you added them through code, can you post a snipped of your html code? – AncientRo Mar 30 '17 at 18:42
  • @AncientRo thanks. Sure. In sentence form, I'm trying to allow my user to create their site layout from a post type itself. So my post type is actually "post-type-layout". When a user creates a layout in that post type I want to store the post id from that post and add it into a get_option(). Then when the site determines which layout to load I will simply get the post id from the get_option(). Then I will know which post id to get the post meta from for the layout options created in that post-type-layout post. Hope that makes sense. Sounds a bit tongue twister on words. – Fearless Mode Mar 30 '17 at 19:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.