Custom fields & ACF on a Single Layout: Loop a post type filtered by another post type

Hi!

I am trying to solve this, but for now without luck. It would be great if you had an idea how to go about it. :slight_smile:

I have a post type called Testimonials.

I have another post type called Therapists.

image

On the Therapists single layout, I need a Looper that displays the testimonials, but only those that are related to a particular Therapist.

So far, I have created an ACF relationship filled on the Testimonials layout where I can select which Therapist the testimonial is about. I choose the Therapist from the list, populated from the Therapists post type. However I am struggling how to use that data on the therapists layout, to display the relevant testimonials.

Any pointers would be appreciated. :slightly_smiling_face:
Thanks!

1 Like

Hi @Misho,

Unfortunately, the given credentials are not working. Can you please check and send it once again.

Thanks

Sure. Updated. Sorry, not sure what has happened there.

Thanks!

HI Misho,

From what I have understood from your query, you need to display some chosen testimonial and display it to your Therapists single page. Please see the recommendation below.

1.) You need to create a Relational field in ACF that will filter the Testimonial post type and assigned it to your Therapists post type.

2.) After creating the field, it will show the lists of testimonials on your Therapist pages.

3.) Create a section of your looper consumer and select the Relational field you created in number one.

For example, your relational field name “testimonial_data

Then in your looper provider, choose the dynamic content and add the dynamic content.
{{dc:acf:post_field field=“testimonial_data”}}

image

4.) Add a text or raw element for your looper consumer. Then to get the title from the Testimonial post type, just use this dynamic code {{dc:post:title}}

5.) Since there’s no dynamic content to get the post content, you need to create a custom shortcode in your functions.php

Something like this one:

function get_data() {
	the_content();
}
add_shortcode('custom_content', 'get_data');

then add the [custom_content] shortcode to your text or raw element, to show the post content.

Hope that helps.

Thank you.

1 Like

Hi! Thank you for your reply!

The way you are describing it is the next best thing to do. However, my aim was to display the testimonials automatically on each therapist’s page.

Testimonials are assigned to individual therapists, by the use of the relationship field. So if the Testimonial was made for Amanda, I have a relationship field on the Testimonials post-type that allows me to choose Amanda from the list. Now the testimonial is related to Amanda.

Now my aim to use that fact, to display all the Amanda’s testimonials back on the Amanda’s therapist page, automatically as they are being added.

Debug consumer is not returning the contents of the Relationship filed, so I don’t see a way to pick anything up for the filters. I was originally planning to match the Therapist title to the one from the relationship field, so I filter out only Amanda’s testimonials on the Amanda’s Therapist page.

I hope this clarifies it. Thank you for being super-helpful!

Hi Misho,

Thanks for your wonderful explanation! Regretfully, what you are trying to achieve isn’t feasible because the ACF relational field isn’t a parent-child relationship. I suggest that you just follow my recommendation above for a workaround.

Hope that helps.

Thank you.

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.