Support » Fixing WordPress » Custom field values in admin columns

  • Hey

    I’ve added a custom post type that’s working fine. For a final tweak I’d like to use show some of the custom field values in columns in the post manager.

    this is the code i have for the columns…but i’m not sure how to get custom field values to show.

    add_action("manage_posts_custom_column", "my_custom_columns");
    add_filter("manage_edit-candidates_columns", "my_candidates_columns");
    
    function my_candidates_columns($columns)
    {
    	$columns = array(
    		"cb" => "<input type=\"checkbox\" />",
    		"title" => "FAB ID",
            "name" => "Name",
    		"area" => "Area"
    	);
    	return $columns;
    }
    
    function my_custom_columns($column)
    {
        global $post;
    
        $cname = get_post_meta($post->ID, 'cname', true);
        $carea = get_post_meta($post->ID, 'carea', true);
    
    	if ("ID" == $column) echo $post->ID;
    	elseif ("name" == $column) echo $cname;
    	elseif ("area" == $column) echo $carea;
    }

    the problem is somewhere with the get_post_meta…not sure what the solution would be.

    any idea would be greatly appreciated

    thanks in advance

Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Custom field values in admin columns’ is closed to new replies.