8th Mar '24
/
0 comments

Related Posts in Bricks using Post Object in a ACF Repeater

In the Bricks forum a user asks:

Hello,

I have an ACF repeater field with name book_translations. Inside that I have a Post Object field where I select a related woocommerce product for a post and has name book_for_selected_language. In the front end I’m trying to output the featured image of the selected product using an image element and the dynamic shortcode {acf_book_translations_book_for_selected_language} but nothing is rendering.

How can I get the featured image from the post object that lies inside a repeater field? Do I need to write a custom function and call it using echo?

This Pro tutorial for Bricks users provides the steps to output posts of another post type related to the current single post via ACF Post Object sub field inside a Repeater.

If the multiple posts selection setting is enabled for the Post Object-type sub field, follow Related Posts using ACF Post Object in Bricks tutorial instead.

In this example, we shall output products related to the current single post being viewed.

ACF field group:

Set the Post Object field's Return Format to Post ID.

When a post is being edited:

Output on the front end after implementing the tutorial:

The Section will be set to output conditionally only if there is at least 1 related product.

We shall also ensure that 's' gets added to the 'Related Product' heading text if the number of matching or related products for the current post is more than 1.

Both Products element (screenshot) and query loop methods are covered.

Step 1

Add the following in child theme's functions.php (w/o the opening PHP tag) or a code snippets plugin:

This is a BricksLabs Pro tutorial.

For full access login below or create your BricksLabs Pro account

Get access to all 610 Bricks code tutorials with BricksLabs Pro

Related Tutorials..

Pro
Conditional Output based on Date Time Picker Field in Bricks

Conditional Output based on Date Time Picker Field in Bricks

In the past, we showed how elements can be conditionally output based on a post's Date type of ACF field here. This Pro tutorial for…
Categories:
Pro
Querying Posts by Date/Datetime Custom Fields in Bricks

Querying Posts by Date/Datetime Custom Fields in Bricks

This Pro tutorial shows how to configure ACF and Meta Box to query posts in Bricks by custom field(s) of the type Date/Date Time Picker…
Categories:
Tags:
Pro
ACF Checkbox Sub Field as Unordered List in Bricks

ACF Checkbox Sub Field as Unordered List in Bricks

Updated on 22 Sep 2023 This Pro tutorial shows how the checked options of a Checkbox-type of Sub Field inside a ACF Repeater field can…
Categories:
Pro
ACF User Field Bricks PHP Query

ACF User Field Bricks PHP Query

In the Bricks Facebook group a user asks: my end goal was to create a set of cards that would display the Users that are…
Categories:
Pro
Conditionally Hiding Bricks Filters based on Select Filter Value

Conditionally Hiding Bricks Filters based on Select Filter Value

How show or hide Bricks' filter based on the selection made by another filter.
Categories:
Tags:
Pro
Related FAQs on Product pages Based on Product Category Taxonomy in Bricks

Related FAQs on Product pages Based on Product Category Taxonomy in Bricks

On product pages, we show all the FAQs associated with the current WooCommerce product's product categories.
Categories:
Pro
Post-specific ACF Repeater Galleries as Sliders in Bricks

Post-specific ACF Repeater Galleries as Sliders in Bricks

How to output ACF Repeater field rows with the images of the Gallery-type sub field as a slider.