Home Forums Backend Issues (wp-admin) Issue | Modify the Relationship Results


Issue | Modify the Relationship Results

  • Hi there Elliot,

    Have added some php to the functions.php file (from your tutorial) in an attempt to modify the html that comes back from the Relationship field in the admin area. I was hoping to pull a thumbnail ( another posts custom field ) and it works as expected, but if you go back in to the post after an post/image has been added to the right-hand side the image is gone and only the text remains.

    function my_acf_relationship_result( $html, $post )
    	// add an image to each result
    	$imagecats = implode(",", wp_get_post_categories($post->ID));
    	$imageobj = get_field('image', $post->ID);
    	$size = "thumbnail"; // (thumbnail, medium, large, full or custom size)
    	$image = wp_get_attachment_image_src( $imageobj['id'], $size );
    	// url = $image[0];
    	// width = $image[1];
    	// height = $image[2]; 
    	if( $image )
    		$html = '<img src="' . $image[0] . '" />' . $html;
        return $html;
    // filter for a specific field based on it's name
    add_filter('acf/fields/relationship/result/name=post_image', 'my_acf_relationship_result', 10, 2);
  • Hi @ebud

    Thanks for the code and description. I can see that you have in the past debugged your code through the print_r function.

    Can you please go through each line of your code and debug it line by line? at which line does the expected result not occur?


Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Issue | Modify the Relationship Results’ is closed to new replies.