Home › Forums › General Issues › Nested Relationships
I have two categories of WooCommerce products: Enclosures and Cameras
Each Enclosure entry has a relationship field product_cameras
, where multiple compatible cameras are selected.
Each Camera entry has a relationship field product_manufacturer
, where a single manufacturer (post) is selected.
My code will pull all the correct camera information, however, I can’t get it to pull any of the information for the manufacturer (it is displaying the title for the enclosure post instead).
Any help is greatly appreciated!
<?php
$featured_posts = get_field('product_cameras');
if( $featured_posts ): ?>
<div class="row justify-content-left">
<?php foreach( $featured_posts as $featured_post ):
$title = get_the_title( $featured_post->ID );
$image = get_the_post_thumbnail_url( $featured_post->ID, 'thumbnail' );
$pdf = get_field( 'product_spec_sheet', $featured_post->ID );
$manufacturer = get_field( 'product_manufacturer', $featured_post->ID );
$logo = get_field( 'manufacturer_logo-darkbg', $manufacturer );
$manuname = get_the_title( $manufacturer );
?>
<div class="col col-sm-3 pb-5">
<div class="card h-100 product-card product-card--camera clear-styles">
<div class="card-body product-card--image">
<img src="<?php echo esc_html( $image ); ?>" class="pb-4">
<img src="<?php echo esc_url( $logo['url'] ); ?>" style="max-height:25px;">
<p><?php echo esc_html( $manuname ); ?> <?php echo esc_html( $title ); ?>
<?php if( $pdf ): ?>
<a href="<?php echo get_site_url(); ?><?php echo esc_html( $pdf ); ?>" target="_blank"><i class="fas fa-info-circle"></i></a>
<?php endif; ?>
</p>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
$manufacturer = get_field( 'product_manufacturer', $featured_post->ID );
$logo = get_field( 'manufacturer_logo-darkbg', $manufacturer->ID );
$manuname = get_the_title( $manufacturer->ID );
Unfortunately, that did not help 🙁
Here’s the updated code:
<?php
$featured_posts = get_field('product_cameras');
if( $featured_posts ): ?>
<div class="row justify-content-left">
<?php foreach( $featured_posts as $featured_post ):
$title = get_the_title( $featured_post->ID );
$image = get_the_post_thumbnail_url( $featured_post->ID, 'thumbnail' );
$pdf = get_field( 'product_spec_sheet', $featured_post->ID );
$manufacturer = get_field( 'product_manufacturer', $featured_post->ID );
$logo = get_field( 'manufacturer_logo-darkbg', $manufacturer->ID );
$manuname = get_the_title( $manufacturer->ID );
?>
<div class="col col-sm-3 pb-5">
<div class="card h-100 product-card product-card--camera clear-styles">
<div class="card-body product-card--image">
<img src="<?php echo esc_html( $image ); ?>" class="pb-4">
<?php if( $manufacturer ): ?>
<img src="<?php echo esc_url( $logo['url'] ); ?>" style="max-height:25px;">
<p><?php echo esc_html( $manuname ); ?> <?php echo esc_html( $title ); ?>
<?php endif; ?>
<?php if( $pdf ): ?>
<a href="<?php echo get_site_url(); ?><?php echo esc_html( $pdf ); ?>" target="_blank"><i class="fas fa-info-circle"></i></a>
<?php endif; ?>
</p>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
Visually, it’s unchanged.
Unfortunately, that did not fix the issue. Here is the updated code:
<?php
$featured_posts = get_field('product_cameras');
if( $featured_posts ): ?>
<div class="row justify-content-left">
<?php foreach( $featured_posts as $featured_post ):
$title = get_the_title( $featured_post->ID );
$image = get_the_post_thumbnail_url( $featured_post->ID, 'thumbnail' );
$pdf = get_field( 'product_spec_sheet', $featured_post->ID );
$manufacturer = get_field( 'product_manufacturer', $featured_post->ID );
$logo = get_field( 'manufacturer_logo-darkbg', $manufacturer->ID );
$manuname = get_the_title( $manufacturer->ID );
?>
<div class="col col-sm-3 pb-5">
<div class="card h-100 product-card product-card--camera clear-styles">
<div class="card-body product-card--image">
<img src="<?php echo esc_html( $image ); ?>" class="pb-4">
<?php if( $manufacturer ): ?>
<img src="<?php echo esc_url( $logo['url'] ); ?>" style="max-height:25px;">
<p><?php echo esc_html( $manuname ); ?> <?php echo esc_html( $title ); ?>
<?php endif; ?>
<?php if( $pdf ): ?>
<a href="<?php echo get_site_url(); ?><?php echo esc_html( $pdf ); ?>" target="_blank"><i class="fas fa-info-circle"></i></a>
<?php endif; ?>
</p>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
Visually, it’s unchanged.
You must be logged in to reply to this topic.
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.