Home › Forums › Front-end Issues › Get Relationship from another Relationship › Reply To: Get Relationship from another Relationship
This is the code I ended up with based on what I assumed the structure should be:
<?php
$items = get_field('add_to_collection');
if($items) {
foreach ($items as $i) {
$artists = get_field('fan_artist', $i->ID);
$size = 'lisf_thumbnail';
if($items) {
$collected_artists= array();
foreach ($items as $item) {
if (!is_array($item->ID, $collected_artists)) {
$collected_artists[] = $item->ID;
}
}
}
}
}
if ($collected_artists) {
foreach ($collected_artists as $artist_id) {
echo get_permalink($artist_id->ID); echo get_the_post_thumbnail($artist_id->ID, $size);
echo get_permalink($artist_id->ID); echo get_the_title($artist_id->ID);
}
}
?>
I’m sure it’s wrong but I can’t necessarily figure out why. It’s outputting the data for the Collection itself instead of the Fan Artist for one, no matter which return format I use.
Also, I refer directly to the Fan Artist relationship in the $artists variable but don’t repeat it further down, as in your code you have $items/$artist_id
When using the brackets system for if statements etc, it also won’t let me use html within the code. How can I use html with this formatting?
Lastly, I’m getting this PHP warning too:
“Warning: is_array() expects exactly 1 parameter, 2 given in… etc”
I’m sure it’s getting close but, as I say, I just need help with the formatting/structure because I can’t figure it out so I’d really appreciate it if you could post full code for how you think it should be.
Thanks a lot.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.