Support

Account

Home Forums ACF PRO use acf form to selectively edit some fields only — Gallery field

Unread

use acf form to selectively edit some fields only — Gallery field

  • Hello,

    I have a Custom Post Type that I’ve extended with an ACF Gallery field so that a random number of images can be entered.
    Each image in the Gallery field has been extended with an ACF WYSIWYG field (for commentary)

    I need to make a front-end form that shows the images from the Gallery, but I only want to allow the viewer to edit the ACF WYSIWYG fields that are associated with each image in the Gallery…and not be able to edit the images from the front end.

    I tried using code from this forum post:
    Use acf_form to build a form to edit particularly fields only

    And I end up with only one editable WYSIWYG field when it’s outside my FOR loop, which is not correct because I need 1 WYSIWYG per image. To achieve this I tried placing acf_form() inside the FOR loop. I managed to get unique form ids by iterating a counter, but there are several html elements with non-unique ids within each form, so all of the forms populate with the same value when I edit any one of them. I suspect that I need to pass more specific $options arguments to the acf_form() function, but I’m not sure what those would be.
    . Here’s a link to the test post.

    Here’s my code:

    <?php acf_form_head(); ?>
    <?php get_header(); ?>
    
      <div id="primary">
        <div id="content" role="main">
          <?php /* The loop */ ?>
          <?php while ( have_posts() ) : the_post(); ?>
            <h1><?php the_title(); ?></h1>
            <?php $photos = get_field('photos') ?> //photos is the gallery field
            <?php  
                $count=1;
                foreach ($photos as $key => $value) {
                  echo "<img src='";
                  echo $value[url];
                  echo "' />";
                  echo "<br/>";
                  $ada_expert = get_field('ada_expert', $value['ID']);
                  echo $ada_expert;//publishes WYSIWYG text below image
                  echo "<br/>";
                  $options = array(
                    'field_groups' => array('group_58f7f98741ede'),
                    'fields' => array('field_58f7f98785c8e'),
                    'id' => 'acf-form-'.$count //returns a unique id for each form
                  );
                  acf_form($options);
                  $count++;
                }
            ?>
          <?php endwhile; ?>
    
        </div><!-- #content -->
      </div><!-- #primary -->
    <?php get_footer(); ?>

    Any suggestions would be most appreciated.

    Thanks,
    Seth

Viewing 1 post (of 1 total)

The topic ‘use acf form to selectively edit some fields only — Gallery field’ is closed to new replies.