Support

Account

Home Forums General Issues Returning a value from a function in a custom field or metabox

Solved

Returning a value from a function in a custom field or metabox

  • Hello,

    Is there a simple or recommended way to return a value from a function within a custom field or metabox area on the post edit screen?

    For example, I tried using this approach but it doesn’t work:

    function acf_load_shorturl_field( $field ) {
    
        // Get shorturl value
        $field = get_shorturl();
    
        // return the field
        return $field;
    
    }
    add_filter('acf/load_field/name=shorturl', 'acf_load_shorturl_field');

    Thanks for any help or suggestions.

    John

  • Looks like I was close. I needed to set the ‘default_value’ attribute:

    function acf_load_shorturl_field( $field ) {
    
        // Get shorturl value
        $field['default_value'] = get_shorturl();
    
        // return the field
        return $field;
    
    }
    add_filter('acf/load_field/name=shorturl', 'acf_load_shorturl_field');
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Returning a value from a function in a custom field or metabox’ is closed to new replies.