Support

Account

Home Forums Backend Issues (wp-admin) Term field in functions.php Reply To: Term field in functions.php

  • Here’s what I did: (in the plugin file that i use to create my custom post type)

    add_filter( 'manage_speakerCPT_posts_columns', 'my_columns_filter', 10, 1 );
    function my_columns_filter( $columns ) {
     	$column_thumbnail = array( 'thumbnail' => 'Speaker Image' );
    	
            //these 2 lines if you want the photo in front
    	//$columns = array_slice( $columns, 0, 1, true ) + $column_thumbnail + array_slice( $columns, 1, NULL, true );
    	//return $columns;
    
            //this line if you want the photo at the end.
    	return array_merge ( $columns, $column_thumbnail );
    }
    add_action( 'manage_speakerCPT_posts_custom_column', 'my_column_action', 10, 1 );
    function my_column_action( $column ) {
    	global $post;
    	$speaker_pic = get_field('speaker_photo');
    	switch ( $column ) {
    		case 'thumbnail':
    			echo '<img src="' . $speaker_pic . '" width="100" />';
    			break;
    	}
    }

    In the above code for the filter and action my CPT is called speakerCPT, so replace that with your CPT name.
    In the action function, $speaker_pic sets my variable for the ACF field ‘speaker_photo’. which is an image field returning only the url.

    Notice I have a commented out line in the first function. I didn’t know if you wanted the image as the first column or the last so you can choose by changing comments. Right now, photo will appear at the end. DON’T do BOTH.