I have a client using some third party forms that I want to easily drop in places on their site.

To easily update them site-wide I thought I would create an ACF repeater field on an options page with fields for form_id and form_markup that I could use to build the shortcode. The idea being a user could enter just the id of the form in the shortcode and the form would output.

i.e. [form form_id="1"]

The question is: how do I call the proper ID from the array of data? Here’s where I started:

function form_shortcode( $atts ) {

    // Attributes
    shortcode_atts(
        array(
            'form_id'   => '',
        ), $atts
    )

    $forms = get_field( 'forms', 'options' );
    foreach ( $forms as $form ) {
        $form_id = get_sub_field( 'form_id', 'options );
    }

    return $form_id;

}

add_shortcode( 'form', 'form_shortcode' );

I know this isn’t correct, but I’m having trouble figuring out exactly how this should even work logistically. Am I even close?

Read more here: Use ACF array values in shortcode


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: