Home › Forums › Front-end Issues › List terms which also have a certain relationship › Reply To: List terms which also have a certain relationship
I believe it would be easier to just re-list and group the returned relationship value in an array like this:
$result = array();
$relationships = get_field("stockists_participating");
foreach( $relationships as $thepost ) {
$thepost_terms = get_the_terms($thepost->ID, 'countries');
foreach( $thepost_terms as $thepost_term ) {
// initialize if the term not listed yet
if( !isset($result[$thepost_term->slug]) ) {
$result[$thepost_term->slug] = array();
}
$result[$thepost_term->slug]['term'] = $thepost_term;
$result[$thepost_term->slug]['value'][] = $thepost;
}
}
print_r($result);
With that code, you can loop trough the $result
instead. Please take a look at the printed result to see the structure of the data.
I hope this helps 🙂
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.