Support

Account

Home Forums Backend Issues (wp-admin) Triggering the Advanced Custom Fields (ACF) \'acf/save_post\' Action Reply To: Triggering the Advanced Custom Fields (ACF) \'acf/save_post\' Action

  • Yes, acf/save_post is to allow you to do other things related to updating a field or a post. This can be anything that does not create “output” like changing meta data, sending information to a 3rd party API, altering the post in some way.

    If you want to update the meta data or the post then yes, you would use acf/save_post. But updating the post means that you are performing some action that alters the database. Altering the HTML output is not updating the database.

    Going back to your original code

    
    function my_acf_save_post($post_id) {
      console_log("Testing...");
    }
    add_action('acf/save_post', 'my_acf_save_post', 20);
    
    function console_log($output, $with_script_tags = true) {
      $js_code = 'console.log(' . json_encode($output, JSON_HEX_TAG) . ')';
    
      if($with_script_tags) {
        $js_code = '<script>' . $js_code . '</script>';
      }
    
      echo $js_code;
    }
    

    This is attempting to create HTML output during the saving of a post.
    Doing this requires 2 steps
    1) During the save process you store some data in some way
    2) During page display you retrieve that stored data and add it to the page