caldera_forms_do_magic_tag

Caldera Forms -- Responsive, drag and drop form builder.

This filter can be used to change the value of a magic tag. It is called on each magic tag that runs inside of the {summary} magic tag. Note that when using individual magic tags, a magic tag in the form of {field_name:label can be used to get the label, instead of the value of the magic tag.

<?php
/**
 * Change a magic tag value.
 *
 * In this case a field for a custom taxonomy, "cue_type" saves the term ID.
 * This filter function will convert that value to the name of the term
 */
add_filter( 'caldera_forms_do_magic_tag', 'slug_id_to_taxonomy_name', 10, 2 );
function slug_id_to_taxonomy_name( $value, $magic_tag  ) {

    //make sure we only act on the right magic tag, and when we have a valid entry (positive integer)
    if ( '{cue_type}' == $magic_tag && 0 < absint( $value ) ) {

        //attempt to get the term
        $term = get_term( $value, 'cue_type' );

        //make sure we have a term object (not a boolean or a WP_Error object
        if ( is_object( $term ) && ! is_wp_error( $term ) ) {
            
            //reset value to the term name
            $value = $term->name;
        }

    }

    return $value;
    
}

Where Does This Code Go?

When using WordPress hooks to customize Caldera Forms or other plugins you should not modify the plugin files, or you will lose your changes when you update the plugin. Instead you should create a small plugin to hold the custom code. It's easy, learn how here.

Technically you can add the custom code to your theme's functions.php, but then you will not be able to change your theme and keep these customizations.

Learn More