Support

Account

Home Forums ACF PRO Render CPT with ACF in Post Object field backend

Unread

Render CPT with ACF in Post Object field backend

  • 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 */
    
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.