Support

Account

Home Forums General Issues acf/load_value php error

Solving

acf/load_value php error

  • Hello, can someone explain to me why the code below doesn’t work (and fix if possible)? Thanks.

    function my_acf_load_value2( $value, $post_id, $field )
    {
    if( is_user_logged_in() ) {
    $user = wp_get_current_user();
    $roles = ( array ) $user->roles;

    $user_id = $user->ID;

    $vara = get_field(‘vara_de_atuacao’, ‘user_’. $user_id);

    $field[‘default_value’] = $vara;
    return $field;
    }
    }
    add_filter(‘acf/load_value/name=vara_de_atuacao’, ‘my_acf_load_value2’, 10, 3);

  • You cannot alter the default value of a field in the load value filter. You can only alter the value.

    Explanation: When using filters in WP only the first argument passed to the filter can be returned and it needs to be the correct format for that argument that the calling function expects. In this case $value is likely a string value and you are attempting to return a field object (array) and this is likely the cause of your error.

    Try using an acf/prepare_field filter instead if you want to alter the field’s default value.

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

The topic ‘acf/load_value php error’ is closed to new replies.