ACF Relationship loop display by custom taxonomy term

Hi,

Is there a way to use an acf_relationship loop and display by a specific term of a custom taxonomy. I’m trying something like this, but it’s show all related posts of that type.

<Loop acf_relationship=related_resources taxonomy=resource-format terms=video orderby=date order=desc>
  <li><a href="{Field url}"><Field title /></a></li>
</Loop>

Any insights appreciated. Thanks!

I don’t believe the acf_relationship loop is able to accept query parameters like other loop types can, which means that you can’t just port over query parameters from the post loop, unfortunately. I’m pretty sure the idea is that that loop type allows you to loop through data exactly as it’s entered into ACF.

If you just wanted to filter the results, you could have some conditional logic within your loop to accomplish that, but that wouldn’t allow your sorting to work.

You know what might work. You could use your acf_relationship loop to create an array of post IDs. Then you could either save that as a variable or pass that directly to the value of the id parameter in a post loop. Then instead of dealing with a acf_relationship loop that doesn’t accept those query parameters, you’d be working with a regular post loop (filtered to only the posts in your ACF relationship field) so you could use all those query parameters. Let me know if that works out for you!

Hi @danaskallman, I was thinking about this a bit more today and I realized that the data within an ACF relationship field is already saved as an array, so there wouldn’t even be a need to use the List tag or something to create the array, you could just pass the field directly to the id parameter. So something like this would probably work for you (you might have to swap out resources since I’m not sure what post type you’re looping through):

<Loop type=resources id="{Field related_resources}" taxonomy=resource-format terms=video orderby=date order=desc>
  <li><a href="{Field url}"><Field title /></a></li>
</Loop>

Let me know if that works for you!

1 Like

Thanks @benjamin for adding this, that did it! :pray:

1 Like