• Hello. I am setting up a page that will use ACF repeater fields, and I’d like to make it so that the user sees a list of subfields, and then if they click on one subfield, they get the description for that subfield to expand and ONLY that description. However, because it’s a repeater field, when I add additional fields and I go to expand, all the fields expand. I can’t figure out a way to assign a random class to each repeater field…

    Is this possible?

    https://www.ads-software.com/plugins/jquery-collapse-o-matic/

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Baden

    (@baden03)

    Not sure what ACF repeater fields are, might you share a link?

    Thread Starter sumydesigns

    (@sumydesigns)

    https://www.advancedcustomfields.com/

    So, when the site owner goes to their page, they can enter text into fields that I set up. The repeater part is that they can click “add row” and add another row. Then when I code the page, it will loop all the entries in those fields.

    I am working on a temporary URL right now – can you email me and I can send you a link? [ redacted, support is not offered via email ]

    Plugin Author Baden

    (@baden03)

    ok, so then you are building the collapse elements programatically?
    Are you using the roll-your-own method, or the shortcode?
    IF you are using the shortcode, are you assigning an id attribute? If you don’t assign an ID, the shortcode will assign a (99% unique) random ID.

    Thread Starter sumydesigns

    (@sumydesigns)

    I’m rolling my own!

    Thread Starter sumydesigns

    (@sumydesigns)

    See code below. It will repeat the entries they enter into the ACF. So if there are two or three entries into the “job openings” field, then it’ll display two or three titles and descriptions. What I want is for all the job openings to show, then the descriptions to expand. But so far, when you click on any title, all the descriptions expand.

    <?php if(get_field('job_openings')): ?>
    
    	<?php while(has_sub_field('job_openings')): ?>
    
    <div class="collapseomatic" id="careers"><?php the_sub_field('openings'); ?></div>
    
     <div class="collapseomatic_content" id="target-careers"><?php the_sub_field('job_description'); ?></div>
    
    	<?php endwhile; ?>
    
    <?php endif; ?>
    Plugin Author Baden

    (@baden03)

    Clearly this is because you are assigning every element the same id of ‘careers’ elements should have unique id names. Try this:

    <?php if(get_field('job_openings')): ?>
    	<?php i = 1; ?>
    	<?php while(has_sub_field('job_openings')): ?>
    <div class="collapseomatic" id="careers<?php echo i; ?>"><?php the_sub_field('openings'); ?></div>
     <div class="collapseomatic_content" id="target-careers<?php echo i; ?>"><?php the_sub_field('job_description'); ?></div>
    	<?php i++; ?>
    	<?php endwhile; ?>
    <?php endif; ?>

    Now with each loop we are tacking on a number that increases.
    Can you dig it?

    Thread Starter sumydesigns

    (@sumydesigns)

    This makes total sense to me, but it’s not working… getting a syntax error when I put it in.

    Thread Starter sumydesigns

    (@sumydesigns)

    Nevermind, I got it! Needed a $ on the i. It’s working now. Thank you SO much! I really appreciate your help, Baden. You are my new best friend. ??

    Plugin Author Baden

    (@baden03)

    yay! friends are my favourite ‘things’ to collect.
    https://myspace.com/maxstalling/music/song/travelin-lite-47203077-50597874

    yes, myspace… crazy, no?

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Use Collapsomatic with ACF Repeater fields’ is closed to new replies.