I have an ACF relationship
field called products
. This field is present on the custom post type called resources
.
In resources
, I have three blogs, titled:
- Blog 1
- Blog 2
- Blog 3
Blog 1 has the products
field set to "Premium". Blog 2 also has this field set to "Premium".
Blog 3 has the products
field set to "Common".
I've made a custom module that will showcase "related products" (blogs that have matching products
). For example, if I'm on Blog 1, I'm expecting to see the title of Blog 2 in this custom module because of the products
field match (they're both set to "Premium").
If I'm on Blog 3, I expect to see nothing, because no other post exists with the products
value.
Currently, in my custom module (called "related products" for reference),I have the following code:
$posts = get_field('products');
if( $posts ):
foreach( $posts as $post):
the_title();
endforeach;
endif;
Now, I'm on Blog 1 and in the "related products" module, I see: Premium
printed once.
It's clearly pulling the data but I think this is only for the current post (it's showing the product
data for blog 1). I've tested this by changing products
on Blog 3 to "Premium" and the results were still the same on-page, just "Premium" printed once on the post.
What I'm trying to achieve:
- Get other posts that are the same
product
type. - Extract data from these other posts (I want to get those post titles and display them).