Support

Account

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

Helping

Issue | Modify the Relationship Results

    • ebud

    • December 4, 2013 at 3:06 am

    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;
    	}
     	//print_r($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);
     
    //*************************************************//
    
    • Elliot

    • December 4, 2013 at 11:03 am

    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?

    Thanks
    E

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

You must be logged in to reply to this topic.

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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.