- This topic has 3 replies, 2 voices, and was last updated 3 years, 10 months ago by
Fernando.
-
AuthorPosts
-
April 7, 2022 at 12:20 am #2180644
Traci
I have custom post types for SIRES, DAMS, LITTERS.
I have an Element Block -> content template I am building to display all litters on the litter archive.
In each Litter I have a relationship with one Sire and one Dam. On the litter listing page, I would like the name (post title) and image (featured image) displayed for each Sire and Dam associated with the litter. Currently, I have selected Dynamic test type: Post Meta, and inserted father in the Meta Field Type (father is the name of the relationship field in the Litter custom field group), but all that shows on the front end is “Array”.
Am I able to pull in relationship values from ACF into GeneratePress Elements? If so, can you help me with what value I need to put into the Meta Field Type to get the actual information from the related post type to display?
Thanks in advance.
April 7, 2022 at 1:52 am #2180710Fernando Customer Support
Hi Traci,
You can retrieve values from ACFs through Dynamic Headlines, however there are limitations. One of them would be arrays.
To address this, One approach is to create a Portable Hook through PHP code:
function your_shortcode($atts, $content = null) { ob_start(); do_action('hook_name'); return ob_get_clean(); } add_shortcode('portable_hook', 'your_shortcode');Now, we can use this
portable_hookin our Content Template as such: https://share.getcloudapp.com/jkuvm5l6Then, we can retrieve the post meta manually through a Hook Element hooked to
hook_namewhich is our portable hook: https://share.getcloudapp.com/kpuJ4g4DAn example code would be:
<?php $relationships = get_post_meta(get_the_id(),'myrelationship',true); foreach($relationships as $relationship){ echo '<p class=relationships>' . get_the_title($relationship) . '</p>'; } ?>This code would retrieve all relationships and place them in a
ptag. With this code hooked to ourportable_hook, the specific relationships of your CPT should now appear.Kindly modify this code to your preference.
Hope this helps! 🙂
April 12, 2022 at 7:07 pm #2186963Traci
Thanks I used a variation of this to work.
April 12, 2022 at 7:25 pm #2186972Fernando Customer Support
You’re welcome Traci! Glad to be of assistance! 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.