Support

Account

Home Forums ACF PRO ACF image as custom column on admin screen.

Solved

ACF image as custom column on admin screen.

  • I have created a custom post type and I’m trying to get an image selected from ACF as the column thumbnail. I do not want to use the featured image as it is already being used in a way that does not make it suitable for the column thumbnail.

    I have this code in my functions.php which adds the new column:

    /*-------------------------------------------------------------------------------
    	Custom Columns
    -------------------------------------------------------------------------------*/
    
    $model_pic = "<?php get_field('model_photo'); ?>";
    
    add_filter( 'manage_edit-model_columns', 'my_columns_filter', 10, 1 );
    function my_columns_filter( $columns ) {
     	$column_thumbnail = array( 'thumbnail' => 'Model Photo' );
    	
    	$columns = array_slice( $columns, 0, 1, true ) + $column_thumbnail + array_slice( $columns, 1, NULL, true );
    	
    	return $columns;
    }
    add_action( 'manage_posts_custom_column', 'my_column_action', 10, 1 );
    function my_column_action( $column ) {
    	global $post;
    	switch ( $column ) {
    		case 'thumbnail':
    			echo '<img src="' . $model_pic . '" width="100" />';
    			break;
    	}
    }

    Everything seems to be working except the image does not show a url source, it’s blank:

    No Source URL

    I have the Return Value for the ACF image field set for Image URL.

    I have tried everything I can find about displaying media objects and everything I try is not working. Is this not possible maybe?

    Thanks in advance

  • did it works when you do this:
    delete $model_pic = "<?php get_field('model_photo'); ?>";
    and add $model_pic = get_field('model_photo'); after global $post;

    but i know it is possible

  • Yes, Mediawerk. Thank you so much. it works.

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

The topic ‘ACF image as custom column on admin screen.’ is closed to new replies.