Home › Forums › General Issues › Relationship Field on single-cpt.php › Reply To: Relationship Field on single-cpt.php
Hi @seasterling
You need to get the collection first, then get the relationship field that is assigned to the collection like this:
// Get the collections first
$collections = get_posts(array(
'post_type' => 'scpl_collection',
'meta_query' => array(
array(
'key' => 'products',
'value' => '"' . get_the_ID() . '"',
'compare' => 'LIKE'
)
)
));
// Loop through the collections
foreach( $collections as $collection ){
// Get the relationship value (products)
$products = get_field('relationship_field_name', $collection->ID);
// Loop through the products
foreach( $products as $product ){
// Do anything you want with the product
}
}
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.