Archived topic
Show content from ACF relationship field
11 replies · Started by Jens on March 20, 2023
Dear Generatepress team,
I am trying to use the GB Query Loop to show featured image, title and excerpt from custom post type (education) that is linked via an ACF relationship field in another custom post type (jobs) one each job's single.
I have tried to use https://generatepress.com/forums/topic/acf-relational-field-output-via-generateblocks-dynamic-data/. Can you give me some more information how to get this to work.
Thanks in advance.
Hi Jens,
Make sure my-class-name is added as a class to the Grid Block of the Query Loop Block.
Adding Custom Classes: https://wordpress.com/support/wordpress-editor/adding-additional-css-classes-to-blocks/
Then replace my_relationship_field in the code with the slug name of your Relational Field.
#2 in the instructions by David is adding a PHP Snippet. Adding PHP: https://docs.generatepress.com/article/adding-php/#code-snippets
Hi Fernando, thanks for the quick reply. I have checked the implementation again. Unfortunately it is not working according to the instructions.
It would be great if you could have a look. You find more info in the private information. Many thanks in advance!
Can you try placing the Relationship field outside the Group field?
Thanks for the tip. I have placed it outside the group field. Now the field is also directly show in the dropdown options of "Post Meta Field". But it still does not show anything on the single.
Hi there,
in the code snippet, immediately after this line:
$relationship = get_field( $relation, $queried_object );
Can you add:
var_dump($relationship);
This will dump that variables value to the page, so we can then see what is inside it.
Thanks! Done.
So thats nothing then :)
Try changing this line:
$relationship = get_field( $relation, $queried_object );
to:
$relationship = get_field( $relation );
Thanks for the effort so far! Unfortunately that did not do the trick. Do you have any further ideas? Thanks in advance.
Hi Jens,
To test, can you try creating a new Relationship field, and test the code on this new one?
Make sure to set a value for it on the CPT you're testing.
Hi Fernando, that also does not work. I will reach out to a developer to have a deeper look. Thanks for your support.
I see. You're welcome, Jens!