Error add_action( 'rwmb_*****_before_save_post' does not work

Support Meta Box AIO Error add_action( 'rwmb_*****_before_save_post' does not work

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #40220
    justdoit123justdoit123
    Participant

    I follow this article https://docs.metabox.io/actions/rwmb-before-save-post/

    and add this code with my group custom field ID, but i cannot set value for custom field text "add_new_contact"

    I tried with another field but cannot set value too

    please check and fix

    add_action( 'rwmb_m_contact_before_save_post', function() {
        $_POST['add_new_contact'] = 0;
       $_POST['test_field'] = 'test';
    } );
    #40232
    PeterPeter
    Moderator

    Hello,

    Thanks for your feedback.

    I also do not see it works on my demo site, please try to use the hook rwmb_after_save_post and the WordPress function update_post_meta() to set/update a field value.

    Please read more on the documentation https://docs.metabox.io/actions/rwmb-after-save-post/

    #40350
    LucaLuca
    Participant

    Hi,
    this didn't work for me either.

    After digging deeper into the problem, I noticed that the saved values are retrieved from the RWMB_Request object and that this is not updated after calling the 'before_save_post' action.

    I have explicitly called the update of the Post values of the object calling the method set_post_data()

    You could try and change your code as follows:

    
    add_action( 'rwmb_m_contact_before_save_post', function() {
       $_POST['add_new_contact'] = 0;
       $_POST['test_field'] = 'test';
    
       if ( function_exists( 'rwmb_request' ) ) {
          rwmb_request()->set_post_data( $_POST );
       }
    } );
    


    @justdoit123

    Please, let me know if this corrects the problem on your side.


    @Peter

    Please, update the documentation or fix the problem, thanks.

    #40351
    PeterPeter
    Moderator

    @Luca: thanks for your feedback. I've informed the development team to check the issue and update the documentation then.

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.