Search code examples
wordpressfunctionadvanced-custom-fieldscustom-fields

Is it possible to call a custom field from ACF or Pods into a function?


I am fluent in HTML and CSS but not so much in PHP. Any help would be appreciated.

I have a custom function in Wordpress as seen below:

function prefix_calculation_global_calculation_vars( $vars ) {
    return array(
        'setup_cost' => 200,
    );
}
add_filter( 'pewc_calculation_global_calculation_vars', 'prefix_calculation_global_calculation_vars' );

Is it possible to call an Advanced Custom Fields (ACF) field or a Pods field and have the value inserted into the function above where the 200 is?


Solution

  • Providing get_the_ID() works you could try this:

    function prefix_calculation_global_calculation_vars( $vars ) {
        return array(
            'setup_cost' => get_field('setup_cost', get_the_ID()),
        );
    }
    add_filter( 'pewc_calculation_global_calculation_vars', 'prefix_calculation_global_calculation_vars' );