- This topic has 8 replies, 2 voices, and was last updated 2 years, 6 months ago by
David.
-
AuthorPosts
-
February 23, 2023 at 3:19 am #2543754
Simon
Hello,
I am looking to link 2 Custom Post Types: Case Studies and Testimonials.
At the bottom of each Case Study, I would like to post a related testimonial.I use ACF Pro, GeneratePress Premium and GenerateBlocks Pro.
I created ACF fields for Case Studies and for testimonials.
For the Testimonials content type there are 3 fields: a field for the testimonial text, a field for the name and a field for the function.
Among the Case Studies fields, I created a Relationship ACF Field that filters by the Testimonials content type and returns the Post ID.
When I edit a Case Study, I can choose the testimonial associated with it.The presentation of each Case Study is managed by a GeneratePress Element of type Block Content Template.
My question: How can I display the ACF fields (text, name, function) of the associated testimonial in the Case Study Content Template?
Thank you
February 23, 2023 at 9:09 am #2544286David
StaffCustomer SupportHi there,
hmmm… so GenerateBlocks Dynamic Data doesn’t support all Pro ACF options yet, such as Relationships.
What you could try is:1. Use a Query Loop block. Set its Params for post type and number of posts, and nothing else.
2. Use a filter to merge its query args to include your Relationship post ID:
add_filter( 'generateblocks_query_loop_args', function( $query_args, $attributes ) { // find the block with <code>my-class-name</code> if ( ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'my-class-name' ) !== false && ! is_admin() ) { // get the relate post ID $queried_object = get_queried_object () ; $relationship = get_field( "related", $queried_object ); // Merge the current $query_args with the new args return array_merge( $query_args, array( 'post__in' => $relationship, ) ); } return $query_args; }, 10, 2 );
NOTE: that you set your
my-class-name
and that needs to be added to the Query Loop -> Grid Block –> Advanced > Additional CSS Classe
And update theget_field
value for your ACF Field.3. Then in that Query Loop you should be able to set the Dynamic data you need on the relevant GB blocks..
But i have not tested this….
March 2, 2023 at 7:42 am #2552759Simon
Hello,
First, I apologize for my late return.
I had to step away from the screen for several days.I have tried to apply your method but so far without success.
I have attached the captures of my configuration:
https://drive.google.com/drive/folders/1rE0kawuUBTkAXqZyodrLfPcWs6xpU3Kf?usp=sharingThanks
March 2, 2023 at 9:50 am #2553061David
StaffCustomer SupportWhat happens if you change the custom fields Return Type to
Post ID
?March 2, 2023 at 10:16 am #2553096Simon
No sorry, nothing is returned (nothing is displayed).
March 3, 2023 at 2:12 am #2553735David
StaffCustomer SupportI made an edit to the PHP Snippet above
Can you try that ?
March 3, 2023 at 3:28 am #2553821Simon
Helo,
Great, it works.
Maybe the first version of your code worked.
I actually found that in my Query Loop I should not choose the content type that contains the repeater field (Case Studies) but the content type that is referred to in the repeater (Testimony).
The parameters that are shown in capture 03-query-loop.png are apparently not good.Anyway it works with the latest version of the code and the repeater field set to Return Format: Post ID.
I take this opportunity to ask you if you have any hints about the release of a new version of GenerateBlocks compatible with the advanced fields of ACF (Repeater, Relationship, Flexible Content…).
Thanks again for your help.
March 3, 2023 at 3:28 am #2553822Simon
Solved
March 3, 2023 at 5:43 am #2553986David
StaffCustomer SupportMy first code was using the wrong parameter, cause i was being stupid lol
We’re currently working on Dynamic Data options to give them way more flexibility then they have.
Once thats done we will be revising the Query Loop so it can handle other content types, not just posts.So its not going to be real soon, but its high on our list for this year. I hope sooner rather than later.
-
AuthorPosts
- You must be logged in to reply to this topic.