Getting related post • Various scenarios with ACF & Toolset

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.

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:

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.

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.

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:

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

Some Updates on this.

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

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

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

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.

1 Like