Not able to get post_id in config as documented

Support MB Frontend Submission Not able to get post_id in config as documented

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #9385
    calpaqcalpaq
    Participant

    Hi Support,
    As per documentation rwmb_frontend_after_process on https://docs.metabox.io/extensions/mb-frontend-submission/ it is stated that $config['post_id'] has the submitted post ID but I am not getting it.

    My task is to update title with meta field called emnsh-name value so that I have tried the above stated hook and I get 0 value of config['post_id'] can you please guide me how do solve this problem

    below is my code
    for custom post type

    add_action ('rwmb_frontend_after_process','emnsh_rwmb_frontend_after_process',10);
    function emnsh_rwmb_frontend_after_process($config){
        if (isset($config['post_id'])) {
            $name = rwmb_meta('emnsh-name');
            wp_update_post(array(
                'ID' =>  $config['post_id'],
                'post_title'=>$name
            ));
        }
      }

    I can see the form values are saved

    Expecting response ASAP
    Thanks

    #9388
    Anh TranAnh Tran
    Keymaster

    Sorry, the docs is incorrect. The submitted post ID is added separately as the 2nd parameter of the hook. Please change the code to this:

    add_action ('rwmb_frontend_after_process','emnsh_rwmb_frontend_after_process', 10, 2);
    function emnsh_rwmb_frontend_after_process($config, $post_id) {
        if ($post_id') {
            $name = rwmb_meta('emnsh-name');
            wp_update_post(array(
                'ID' =>  $config['post_id'],
                'post_title'=>$name
            ));
        }
    }

    I also updated the docs.

    #9393
    calpaqcalpaq
    Participant

    Thanks for immediate response and it solved my problem.

Viewing 3 posts - 1 through 3 (of 3 total)
  • The topic ‘Not able to get post_id in config as documented’ is closed to new replies.