Hello, I have a CPT with ACF fields. I than use the Post Object field within pages to select this CPT. Using the following function I always was able to display / preview some of the ACF fields within that CPT: title, image and year.
Since the latest updates I just see html instead of a render of the actual CPT ACF content.
How can I change this function for it to work? Thanks in advance!
function post_object_with_avatar( $title, $post, $field, $post_id ) {
$post_thumbnail_url = get_field('portfolio_item_image',$post->ID);
$year = get_field('portfolio_item_year',$post->ID);
$dimensions_height = get_sub_field('portfolio_item_height',$post->ID);
$dimensions_width = get_sub_field('portfolio_item_width',$post->ID);
$avatar = '<div class="post_ava_prefilter_wrapper" title="'.$title.'">';
$avatar .= '<div class="ava_prefilter_wrapper"><img src="'.$post_thumbnail_url.'" /></div>'."<b>$title</b>"."<br>"."$year"."<br>"."$dimensions_height";
$avatar .= '</div>';
return $avatar;
}
add_filter('acf/fields/post_object/result/key=field_636bXXX', 'post_object_with_avatar', 10, 4); /* Portfolio-1-a */
add_filter('acf/fields/post_object/result/key=field_6344XXX', 'post_object_with_avatar', 10, 4); /* Portfolio-2-a */
add_filter('acf/fields/post_object/result/key=field_6344XXX', 'post_object_with_avatar', 10, 4); /* Portfolio-2-b */
add_filter('acf/fields/post_object/result/key=field_6344XXX', 'post_object_with_avatar', 10, 4); /* Portfolio-3-a */
add_filter('acf/fields/post_object/result/key=field_6324XXX', 'post_object_with_avatar', 10, 4); /* Portfolio-3-b */
add_filter('acf/fields/post_object/result/key=field_6344XXX', 'post_object_with_avatar', 10, 4); /* Portfolio-3-c */
add_filter('acf/fields/post_object/result/key=field_634bXXX', 'post_object_with_avatar', 10, 4); /* Portfolio-4-a */
add_filter('acf/fields/post_object/result/key=field_634bXXX', 'post_object_with_avatar', 10, 4); /* Portfolio-4-b */
add_filter('acf/fields/post_object/result/key=field_634bXXX', 'post_object_with_avatar', 10, 4); /* Portfolio-4-c */
add_filter('acf/fields/post_object/result/key=field_634bXXX', 'post_object_with_avatar', 10, 4); /* Portfolio-4-d */
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.