ACF relationships

I added a couple of ACF fields relationships in Woocommerce product.
The relationship link to a feature image of another CPT.
In the product background, I have no problem to list and select the image I want:

That is great, but in a template, I created a Query on products and I can’t display these images.
Whatever I select, the image is empty.

Could you help me please.

Hi @weedor,

This might be of help: ACF | Querying relationship fields

More specifically, the query arguments they use:

							'post_type' => 'doctor',
							'meta_query' => array(
								array(
									'key' => 'location', // name of custom field
									'value' => '"' . get_the_ID() . '"', // matches exactly "123", not just 123. This prevents a match for "1234"
									'compare' => 'LIKE'
								)
							)
1 Like

Thank you @Louis
That seems very detailled and I think that I will find my solution.
As soon as I reach it (no doubt!) I will keep you posted.

Super @weedor!

Just to add, if you are querying products, you will have to add an inner query with the relationship arguments.
If you need more specifics, let me know.

Yes I did
The query for product is:

<?php 
// The Arguments
$args = array (
  'category' => 
  array (
    0 => 'events',
  ),
  'orderby' => 'date',
  'order' => 'ASC',
);
// The Query
$the_query = new WC_Product_Query( $args );

I have not yet taken a look to the post you sent.
I will tell you if I stuck somewhere…
Thank you for your concern even for support to ACF that is not really yours.

I found out the solution via the link that you posted and everything works fine.
I thank you again for the support that you give all days long and all weeks long.
That’s appreciate.
I will write a tuto or a video to explain how to use the ACF relationship and post it here.
As soon as it will be done, I will post the topic as resolved.

1 Like

Here is the code:

<?php $field = ''; ?>
<?php $fields = ''; ?>

<?php $fields = get_field('evenement'); ?>
<?php if( $fields ): ?>
		<?php foreach( $fields as $field ): ?>
				<?php $field_id = $field->ID; ?>
				<?php $image = get_field('_thumbnail_id', $field_id); ?>
				<?php if( $image ) {
					$thumb = $image['sizes'][ 'thumbnail' ]; ?>
					<div>
						<img src="<?php echo esc_url($thumb); ?>" width="80px" height="100%" />
					</div>
				<?php } ?>
		<?php endforeach; ?>
<?php endif; ?>

CPT : type_devenement
PRODUCT: woocommerce

In ACF-type-devenement (post-type=type événement), I defined a field image (slug=_thumbnail_id)

In ACF-product (post-type=product), I defined a field relationship (slug=evenement) with filter per post type = type événement

There is below a screenshot of the product edition and the result (displayed with Admin column pro and the woocommerce addon).

To display in Cwicly, you must set a Query with product and add in the query template a code block with the given code.

Feel free to post if somthing must be clarify or if you have question.