
Are there any guides on how to create a shortcode from a repeater field?
I’m trying to create a repeater field in which the user can create a list in accordion fashion.
Ideally the functionality would be:
– a main repeater field to create accordions,
– a nested repeater field to create each accordion and its items,
– nested repeater field’s fields would be:
– key: id/key to call accordion as shortcode param,
– title: accordion item title and trigger,
– text: accordion togglable body
Ideally, shortcode would be:
[accordion key="key"]
and would output something like this:
<ul class="accordion">
<li>
<h3><a class="trigger" href="#">Lorem ipsum dolor sit amet</a></h3>
<div class="panel">Consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</div>
</li>
<li>
<h3><a class="trigger" href="#">Lorem ipsum dolor sit amet</a></h3>
<div class="panel">Consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</div>
</li>
<li>
<h3><a class="trigger" href="#">Lorem ipsum dolor sit amet</a></h3>
<div class="panel">Consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</div>
</li>
</ul>
Hi @angel.meraz
You can tackle this by breaking it up into 2 parts:
1. Ignore the shortcode and write the code to loop through the repeater fields and output the accordions.
http://www.advancedcustomfields.com/resources/have_rows/
2. Pull out that code and place it in a function within your functions.php file. Then tweak it to work as a shortcode:
http://codex.wordpress.org/Shortcode_API
This reply has been marked as private.