Support

Account

Home Forums General Issues Add ACF Field into PHP (Gravity Forms)

Solving

Add ACF Field into PHP (Gravity Forms)

  • PHP noob here…. and I have a hunch this should be easy.

    I’m making a custom page that is displaying and using some post data and ACF data. In it, I’m dropping a gravity form using:

    <?php gravity_form( $id , false, false, false, '', true, 1 ); ?>

    Where $id represents the form id of the form I want to display on this page. I have an ACF field to define the form id. But I want to define $id from an ACF field.

    This is how I would want it to work, but I know this isn’t proper PHP coding:

    <?php gravity_form( get_field('event_registration_form_id'); , false, false, false, '', true, 1 ); ?>

    So with that, how do I inject the ACF field into the middle of the gravity_form code?

  • I solved this 5min after posting it…

    <?php $form_id = get_field('event_registration_form_id'); ?>
    <?php gravity_form( $form_id , false, false, false, '', true, 12 ); ?>

    Not sure that is the cleanest or ‘proper’ way but it works 🙂 If there is a better way to do it, let me know. Again, php noob here.

  • That’s the way I would do it. Both your first code and second are good, but I like the second better because it’s easier to read and see what’s happening.

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

You must be logged in to reply to this topic.