Found !
It was a mistake by my side. I forget to set the ID in the get_field. In my case I need to pass the ID of a post and I missed this one because I don’t need to specify it in the while statement.
So it works.
Thanks John, and no I’m not working with a nested repeater.
This repeater is in a tab, there’s no particular extra-settings.
You maybe have a beginning of a solution. If I echo the repeater, I get nothing. If I var_dump the repeater, I get NULL. But, I can iterate on it and get all the values.
Fantastic ! I get the object.
But… there’s no value at all in this object. Well the values are NULL in this new array and so when trying to ouptut $sub_field[‘value’]
With the help of a collegue, I rewrote the code for my purpose (and it works) :
function sortByGroup($a, $b) {
if ($a['partner-category'] > $b['partner-category']) {
return -1;
} elseif ($a['partner-category'] < $b['partner-category']) {
return 1;
}
return 0;
}
$partnerArray = get_field('partner');
if (!empty($partnerArray)) {
usort($partnerArray, 'sortByGroup');
$last_group = ''; // initialize the group name
foreach ($partnerArray as $partner) {
$this_group = $partner['partner-category'];
if ($this_group != $last_group) {
$last_group = $this_group;
echo '<h3>',$partner['partner-category'],'</h3>';
}
if ($partner['partner-website']) {
$partner_bloc = '<a href="'.$partner['partner-website'].'">'.$partner['partner-name'].'</a>';
}
echo $partner_bloc;
} // end foreach
} // end if personArray
The line $last_group = $this_group;
was missing in order to display the H3 only one time by group. And the sorting function has been inverted in order to reflect the backend order (from top to bottom).
Hi John, thanks a lot for this piece of code.
It won’t work until we correct the sort function namespace π (sortByGroup and not shortByGroup).
Something else : from this code, the company group (h2) is displayed for every row because it’s in the foreach loop.
Do you think there’s a way to get the value of company group and display it only one time per group ?
Thanks a lot John !!
Hi everyone,
I’m trying to achieve something similar except I want to loop through a subfield which is a choice selection.
I want to display it by row but first by this subfield :
CATEGORY
value
value
CATEGORY
value
Where CATEGORY is the subfield and value are the other subfields of a row.
I tear my hair between the row loop and the choices loop…
Thanks in advance for any help !
Well it doesn’t make sense for me to have a conditional logic because I want to see this comment field always and for all choices fields.
At this point, I don’t know how to achieve that but it’s a matter of time π
Thank you for this answer.
So, what you say is that I can’t achieve that without creating a new field type… that’s something I’m not able to do as I’m not developer.
To get the idea, I want the user to choose a value in a list of choices and optionnaly add a comment. I need this comment to be linked to the field because the display will be not localised at the same place (so I need a reference).
(οΌδΈ_δΈ)
(shame on me)
OK now the value of message field type doesn’t echo.
Is it a different approach than just getting the value ?
Well I think I’ll use value for messages and description for radio buttons.
Because it’s all the types I use.
I got so many fields and they’re displayed in a table so it will be very hard to use that workaround. Thanks anyway !
I have to provide an english translation of every label of every fields.
I thought working with suffix (or prefix) was a good shortcut.
So I need it on every field type (and especially on message and radio button).
Yes ! That’s it…
I forgot to get the value $value = $values[$field['name']];
Thanks a lot
Well I tried this and it gives exactly the opposite behavior : no answer at all, all the cells are empty as if there was no value.
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.