Home › Forums › Add-ons › Repeater Field › Convert raw repeater data back into an array › Reply To: Convert raw repeater data back into an array
@hube2 Here’s what the block’s data looks like from parse_blocks()
:
Array (
[blockName] => site/recipes
[attrs] => Array (
[name] => site/recipes
[data] => Array (
[heading_level] => h2
[_heading_level] => blocks-recipes-heading_level
[items_per_page] => 9
[_items_per_page] => blocks-recipes-items_per_page
[show_pagination] => 1
[_show_pagination] => blocks-recipes-show_pagination
[filter_categories_0_category] => easy_meal_categories
[_filter_categories_0_category] => blocks-recipes-filter_categories-category
[filter_categories_0_easy_meal_categories-value] => 30-minutes-or-less
[_filter_categories_0_easy_meal_categories-value] => blocks-recipes-filter_categories-easy_meal_categories-value
[filter_categories_1_category] => consumer_symbols
[_filter_categories_1_category] => blocks-recipes-filter_categories-category
[filter_categories_1_consumer_symbols-value] => dairy-free
[_filter_categories_1_consumer_symbols-value] => blocks-recipes-filter_categories-consumer_symbols-value
[filter_categories] => 2
[_filter_categories] => blocks-recipes-filter_categories
)
[mode] => preview
)
[innerBlocks] => Array ()
[innerHTML] => EMPTY STRING
[innerContent] => Array ()
)
filter_categories
is a repeater containing a dropdown to select the category and another dropdown to select the value. Each category has its own set of values so there’s a conditional on each value dropdown to match the selected category. That’s why for the value the category name is a part of the key filter_categories_0_<category>-value
. In the above code, there are 2 filters selected, easy_meal_categories = 30-minutes-or-less
and consumer_symbols = dairy-free
.
I realize I could do this the hard way and parse the keys out, but that’s brittle and especially difficult if repeaters are nested.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.