Support

Account

Home Forums ACF PRO Admin Columns & Custom Post Types

Solved

Admin Columns & Custom Post Types

  • Hi

    I am trying to add custom columns to a custom post type of ‘character’.

    I have managed to add 2x new columns but I can’t seem to echo out the thumbnail or text field from the custom post.

    Can anyone tell me what’s wrong with my code please?

    Note: My code is contained within a simple plugin.

    function my_character_columns($columns)
    {
    	$columns = array(
    		'cb'	 	=> '<input type="checkbox" />',
    		'thumbnail'	=>	'Profile Picture',
    		'title' 	=> 'Character Name',
    		'subtitle' 	=> 'Character Sub Title',
    	);
    	return $columns;
    }
    
    function my_custom_character_columns($column)
    {
    	global $post;
    	
    	if($column == 'thumbnail')
    	{
    		echo wp_get_attachment_image( get_field('character_profile_picture', $post->ID), array(200,200) );
    	}
    	
    	elseif($column == 'subtitle')
    	{
    		echo get_field('character_sub_title');
    	}
    	
    }
    
    add_action("manage_character_custom_column", "my_custom_character_columns");
    add_filter("manage_edit-character_columns", "my_character_columns");
  • The hook for the function that shows the column content should be

    add_action("manage_character_posts_custom_column",
        "my_custom_character_columns", 10, 2);

    I also changed it to use 2 parameters because this hook will pass the post id and then you can remove you global statement.

    
    function my_custom_character_columns($column, $post_id)
    
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Admin Columns & Custom Post Types’ is closed to new replies.