Support

Home Forums Event Espresso Premium $_POST[] not returning ACF field value on Event edit page

$_POST[] not returning ACF field value on Event edit page

Posted: January 14, 2018 at 2:28 pm

Viewing 2 reply threads


Patrick

January 14, 2018 at 2:28 pm

Hi, I’m writing a custom script and need to get a field’s value in a callback function on the wp_insert_post_data hook, which is fired before the field is saved using the Save Draft button in the event edit view. For some reason, I am unable to get and ACF custom field using $_POST[] when on an Event edit page. Any help would be appreciated.


Josh

  • Support Staff

January 15, 2018 at 2:41 pm

The fields should be available from $_POST['meta']

If you add the following code to your plugin:

if (!function_exists('write_log')) {
    function write_log ( $log )  {
        if ( true === WP_DEBUG ) {
            if ( is_array( $log ) || is_object( $log ) ) {
                error_log( print_r( $log, true ) );
            } else {
                error_log( $log );
            }
        }
    }
}

add_filter( 'wp_insert_post_data', 'filter_handler', '99', 2 );
function my_filter_handler( $data , $postarr ) {
  global $_POST;
  write_log($_POST['meta']);
  return $data;
}

Then have WP_DEBUG activated with WP_DEBUG_LOG also set to true, does your debug.log file have the meta key and value pair?


Patrick

January 15, 2018 at 5:09 pm

Hi Josh,

Thank you for your debugging recommendation ! I found the problem.

ACF does not use the field name in html forms. The field name is only available when the meta field is saved. Instead, they use this structure : [‘acf’][‘field_xxxxxxxxxx’] where we need to pass the field key as the second identifier. So it is possible to get the form field using $value = $_POST['acf']['field_xxxxxxxxxx'];

Cheers !

Patrick

Viewing 2 reply threads

The support post ‘$_POST[] not returning ACF field value on Event edit page’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso