rwmb_{$field_id}_after_save_field
- This topic has 8 replies, 2 voices, and was last updated 6 years, 3 months ago by
[email protected].
-
AuthorPosts
-
December 10, 2018 at 11:22 PM #12580
[email protected]
ParticipantHi,
Trying to use: rwmb_{$field_id}_after_save_field
field:
array( 'name' => 'Select Level', 'id' => self::$prefix . 'level', 'type' => 'select', 'placeholder' => 'Please select', 'options' => $select ),
$prefix = 'property'
action not working:
function api_check_post_level_updated($field, $meta_value, $old_level, $post_id ) { //Current data $measurements = get_post_meta($post_id, '_property_' . $old_level . '_measurements', true); $bedrooms = get_post_meta($post_id, '_property_' . $old_level . '_bedrooms', true); $bathrooms = get_post_meta($post_id, '_property_' . $old_level . '_bathrooms', true); $currency = get_post_meta($post_id, '_property_' . $old_level . '_currency', true); $booking_url = get_post_meta($post_id, '_property_' . $old_level . '_booking_url', true); $features = get_post_meta($post_id, '_property_' . $old_level . '_features', false); $atnr = get_post_meta($post_id, '_property_' . $old_level . '_atnr', true); $feature_image = get_post_meta($post_id, '_property_' . $old_level . '_feature_image', false); $slideshow = get_post_meta($post_id, '_property_' . $old_level . '_slideshow_images', false); $gallery = get_post_meta($post_id, '_property_' . $old_level . '_images', false); $floorplans = get_post_meta($post_id, '_property_' . $old_level . '_floorplans', false); $floors = get_post_meta($post_id, '_property_' . $old_level . '_floors', false); $facilities = get_post_meta($post_id, '_property_' . $old_level . '_facilities', false); //Copy old level data to new level update_post_meta($post_id, '_property_' . $meta_value . '_measurements', $measurements); update_post_meta($post_id, '_property_' . $meta_value . '_bedrooms', $bedrooms); update_post_meta($post_id, '_property_' . $meta_value . '_bathrooms', $bathrooms); update_post_meta($post_id, '_property_' . $meta_value . '_currency', $currency); update_post_meta($post_id, '_property_' . $meta_value . '_booking_url', $booking_url); update_post_meta($post_id, '_property_' . $meta_value . '_features', $features); update_post_meta($post_id, '_property_' . $meta_value . '_atnr', $atnr); update_post_meta($post_id, '_property_' . $meta_value . '_feature_image', $feature_image); update_post_meta($post_id, '_property_' . $meta_value . '_slideshow_images', $slideshow); update_post_meta($post_id, '_property_' . $meta_value . '_images', $gallery); update_post_meta($post_id, '_property_' . $meta_value . '_floorplans', $floorplans); update_post_meta($post_id, '_property_' . $meta_value . '_floors', $floors); update_post_meta($post_id, '_property_' . $meta_value . '_facilities', $facilities); } add_action('rwmb__property_level_after_save_field', 'api_check_post_level_updated', 10, 5);
any help would be helpful.
thanks
December 12, 2018 at 5:12 PM #12618Anh Tran
KeymasterHi,
Is the
$prefix = property
or_property
?_property
matches the actionrwmb__property_level_after_save_field
(In this case,$field_id
is_property_level
).I see you are trying to copy values from old fields to new fields. Please note that, this action happens after field
_property_level
is saved. It doesn't guarantee that it happens before or after other fields are saved.December 12, 2018 at 5:15 PM #12620[email protected]
ParticipantAh sorry prefix should be _ property _ no spaces.
Ah ok, is there a way I can achieve what I am trying to do it says hook still passes old/new values?
Thanks
December 12, 2018 at 5:19 PM #12621Anh Tran
KeymasterIt's nearly impossible to guarantee the order of fields saved. So I'd suggest using
rwmb_before_save_post
hook to get all the old values of a post before other fields are updated. Then userwmb_after_save_post
to update the needed fields.December 12, 2018 at 5:21 PM #12623[email protected]
ParticipantThanks Anh,
Sorry whats the best way to pass the fields from rwmb_before_save_post to after_save_post?
3 functions?
December 13, 2018 at 4:29 PM #12644Anh Tran
KeymasterJust save it in a temporary variable (a class property if you're using a PHP class, or a global variable if you use normal functions).
December 13, 2018 at 4:37 PM #12646[email protected]
ParticipantThought so, thanks Anh will give it a go and see how we get on.
December 21, 2018 at 11:30 PM #12780[email protected]
ParticipantHi Anh,
Got round to trying this and it seems to run a few times?
https://ghostbin.com/paste/6tcft
Thanks for your help again.
January 10, 2019 at 5:27 PM #12973[email protected]
ParticipantHi Anh,
Still not got it to work all values seem to be passing through but they just aren't saving to the post. Updated code:
-
AuthorPosts
- You must be logged in to reply to this topic.