Support

Account

Home Forums Backend Issues (wp-admin) Test Fire acf/save_post

Helping

Test Fire acf/save_post

  • I am trying to “test fire” a post update event from within a custom post type editor, which includes several ACF custom fields including one based upon an ACF custom field type that I created. When I update one of the ACF custom field values in the editor, I expect the acf/save_post action to fire. Here is the code I have in my theme’s function.php file.

    ‘function my_acf_save_post($post_id) {
    console_log(“Testing…”);
    }
    // Chose a lower priority to ensure callback function is invoked after a post save event
    add_action(‘acf/save_post’, ‘my_acf_save_post’, 20);’

    ‘// Courtesy of Kim Sia
    // (see: https://stackify.com/how-to-log-to-console-in-php/)
    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;
    }’

    I have my web browser’s inspector window open for my custom post type editor. When I alter a ACF custom field value and click “Update” from the custom post editor page, I expect to see Testing… appear in my inspector’s ‘Console’ pane. Unfortunately, this does not occur; neither is any error generated.

    Any thoughts? Thank you.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.