Archived topic
Using ACF relationship loop shortcode in Elements
1 reply · Started by Ossian Ravn on December 22, 2022
Hello,
I am setting up a site (dentist directory) with GP/GB, ACF, and CPT UI. I am however not too experienced with GP/ACF and WP-dev in general so my approach might be off - but there is only one way to learn.
I already have my data imported into the following (simplified) structure:
(Post Type/Field group: Custom fields)
Dentists: Id, OrganizationId, Name
Products: Id, OrganizationId, ProductName
Dentists_Products: Id, OrganizationId, ToPrice
In the field group "Dentists" I have created a relationship field named "Products" and added "Products" and "Dentists_Products" to "Filter by Post Type". The return format is set to "Post object"
In elements, I created a content template named "Dentist content" and inside that, I have added the following shortcode in a p-tag - just for testing, that data is coming through.
[relationship field="products" post_type="dentists_products" filters="organizationid=<?php the_ID(); ?>"]
[loop]
[acf field="productname"]: [acf field="toprice"]
[/loop]
[/relationship]
But when I go to one of the pages for a dentist I get this printed out:
[relationship field="products" post_type="dentists_products" filters="organizationid="]
[loop]
:
[/loop]
[/relationship]
So for some reason, the shortcode is not being recognized. Can anyone point me in the right direction?
Best Regards!
Ossian
Hi Ossian,
For reference, can you provide the link to the "Test" page and the page where the shortcode isn't working?
You may use the Private Information field for this: https://docs.generatepress.com/article/using-the-premium-support-forum/#private-information
The shortcode doesn't work for all types of fields. I'm not sure if it would work as it should for Relationship fields. Reference: https://www.advancedcustomfields.com/resources/shortcode/#limitations
