# Getting related post • Various scenarios with ACF & Toolset

**URL:** <https://forum.bricksbuilder.io/t/getting-related-post-various-scenarios-with-acf-toolset/21950>\
**Category:** How To\
**Tags:** templates, how-to\
**Created:** [April 17, 2024, 9:47am UTC](https://forum.bricksbuilder.io/t/getting-related-post-various-scenarios-with-acf-toolset/21950 "2024-04-17T09:47:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![SVIreland](https://forum.bricksbuilder.io/user_avatar/forum.bricksbuilder.io/svireland/32/17603_2.png) [@SVIreland](https://forum.bricksbuilder.io/u/SVIreland)\
**Post date:** [April 17, 2024, 9:47am UTC](https://forum.bricksbuilder.io/t/getting-related-post-various-scenarios-with-acf-toolset/21950/1 "2024-04-17T09:47:35Z")

</div>

Hi all,

I have been using Toolset for several years now and it’s failry extensive in what you can do with it, once you get down into the weeds with its documentation.

I have the following site which presents my fine fine art prints, catalogued by year:  
[https://www.vaughanprint.com](https://www.vaughanprint.com).

It is built using Divi but I am considering re-themeing it with Bricks. So, an oppertunity to tidy things up using the query loop and possibly migrating to ACF. So far I am getting mixed results. Some of the simpler loops work fine. But trying to replicate some of the finer configured loops, filtered based on the relationships are a bit of a hudle, some success with ACF but other scenarios more easily achieved via Toolset views and templates rendered by droping in shortcodes.

A quick overview.

This uses two CPTs, Prints and Print Years. It is using a Toolset relationship with the slug print-year\_print.

For the Print Year post type I have template that renders like so:

> **[Prints 2021 & 2022 | Vaughanprint](https://www.vaughanprint.com/print-year/prints-2021-2022/)**
>
> All fine art prints made by Stephen Vaughan in 2021

The top view shows a grid of thumbnails for the work made in that year/period. All very straigh forword to set up in a toolset view. Replicated no problem with ACF, but with the advantage of being able to do so directly in Bricks because the relationships based on the relationshop fields get registered in Bricks.

Moving onto the template created for the Print type.

> **[Firestarter | Vaughanprint](https://www.vaughanprint.com/print/firestarter/)**
>
> Firestarter: fine art etching carborundum print by Stephen Vaughan

All very standard stuff here in terms of dynamic data and layout. If you scroll down the page there is another view, much like the one that was on the parent year. Here is where it gets a bit trickier and I had to go in and revisit the original implementation of this, as configured with Toolset. There werre too hoops here. After building out the original view of prints, filtered on the relationship to the parent year. it must be palsed in a Toolset template if it is to render at all. Because this filtered presentation of related (by year) is now on a sibling post the implementation needs an extra step to point back to the parent for reference. This is done by modifying the shortcode:

[wpv-view name=“year-prints”] adding in item=“@print-year\_print.parent” to end up with

[wpv-view item=“@print-year\_print.parent” name=“year-prints”]

This does the trick. It requires a deep knowledge of Toolset developer documentatoin (or help from support), but once you know how to do this it’s fairly straight forward. I’m not seeing anyway to do this in ACF Pro. There are some posts online demonstrating how to do this with PHP but none showing a Bricks/ACF approach to this?

There is the following example showing how this can be done using the query editor (PHP) but it doesn’t give the results I need.

> [@Reverse query with Bricks and ACF Pro](https://forum.bricksbuilder.io/t/reverse-query-with-bricks-and-acf-pro/18278):
>
> Using ACF Pro i have a CPT named Faculty with many Professors (another CPT). This is a one to many relationship field i have in the Faculty fields group. How can i display in the Professor single template the faculty that the professor belongs to ? I have tried to create a query loop with the relationship on the type but it doesn’t work. I have done so in JetEngine that relations are set seperately, but unfortunately i can’t do so in ACF Pro. Any help?

Applied on the Year template it outputs more prints not in the related year. Applied on the Print template it doesn’t produce any results at all.

If anyone else has had a look at this sort of scenario with some success (Information on ACF or Toolset solutions ), some pointers would be appreciated.

The follwoing documentation is available from Toolset:

> **[Post Relationships API - Toolset](https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/)**
>
> Toolset Types provides a Post Relationship API allowing you to use custom PHP for querying related content in a convenient way. This page explains how to

> **[How to Migrate Your Site to New Post Relationships - Toolset](https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/how-to-migrate-your-site-to-new-post-relationships/#public-functions-for-getting-related-posts)**
>
> Toolset Types 3.0 introduces a completely new post relationship features and the new Post Relationship API. This page explains how to migrate existing

I looked through this Toolset documentation but had no look garnering anything from this that would work in the query loop editor(PHP).

---

<div class="post-metadata">

**Author:** ![SVIreland](https://forum.bricksbuilder.io/user_avatar/forum.bricksbuilder.io/svireland/32/17603_2.png) [@SVIreland](https://forum.bricksbuilder.io/u/SVIreland)\
**Post date:** [May 6, 2024, 1:51pm UTC](https://forum.bricksbuilder.io/t/getting-related-post-various-scenarios-with-acf-toolset/21950/2 "2024-05-06T13:51:30Z")

</div>

Some Updates on this.

I have got so far using the following solutions as reccomended by Bricks Labs:

> **[Adding any Custom WP\_Query loop to Bricks' Query Loop - BricksLabs](https://brickslabs.com/adding-any-custom-wp_query-loop-to-bricks-query-loop/)**
>
> Sometimes we may need to create a custom post loop using Bricks' query loop feature, but wish to use our own WP\_Query code for more flexibility. This could either be because we need to do something that the built-in settings don't quite allow for...

For the arguments section I have adapted it to the Toolset’s suggestion as outlined in their documentation:

> **[How to Migrate Your Site to New Post Relationships - Toolset](https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/how-to-migrate-your-site-to-new-post-relationships/)**
>
> Toolset Types 3.0 introduces a completely new post relationship features and the new Post Relationship API. This page explains how to migrate existing

The args in the run\_new\_query function look like this now:

$args = [  
‘post\_type’ =\> ‘print’,  
‘orderby’ =\> ‘desc’,  
‘posts\_per\_page’ =\> ‘-1’,  
‘toolset\_relationships’ =\> array(  
‘role’ =\> ‘child’,  
‘related\_to’ =\> get\_the\_ID(),  
‘relationship’ =\> ‘print-year\_print’  
)  
];

This does return the correct result on the front end, in terms of child posts, but there are still two problems.

• The loop outputs Error: error on the back end.

• That error seems to interfere with the output on the front end in terms of styling. If I apply

---

<div class="post-metadata">

**Author:** ![SVIreland](https://forum.bricksbuilder.io/user_avatar/forum.bricksbuilder.io/svireland/32/17603_2.png) [@SVIreland](https://forum.bricksbuilder.io/u/SVIreland)\
**Post date:** [May 6, 2024, 7:12pm UTC](https://forum.bricksbuilder.io/t/getting-related-post-various-scenarios-with-acf-toolset/21950/3 "2024-05-06T19:12:13Z")

</div>

So Just one more update… I think we are winning here!

My bad on the presentation. I had set the grid on the wrong element, hence my odd layout on the front end. When the brain is tired…

So the only thing now is not seeing anything rendered on the backend just Error: error.

I tried one little trick I added suppress\_filters=“false” into the arguments and this allows me to see the looped items in the backend but, it shows all items outside the confines of just the related child posts to parent, all 216!

So grand for temporarily styling this part of the layout, but if anyone knows of a way to focus on just the related posts let me know.

Also if onyone can give some tips in just using something a lot shorter than Bricks Lab’s version, something that would just work in the PHP Query Loop editor that would be appreciated too.
