• I have the following code, which works approximately as expected:

    add_filter('manage_knowledgebase_posts_columns', 'wpkb_columns' );
    
        function wpkb_columns( $defaults ) {
        	$defaults['upvotes'] = __('<strong>U</strong>');
        	$defaults['downvotes'] = __('<strong>D</strong>');
        	return $defaults;
        }
    
        add_action( 'manage_knowledgebase_posts_custom_column', 'wpkb_custom_columns' );
    
        function wpkb_custom_columns( $column ){
        	global $post;
    
        	switch ( $column )
        	{
        		case 'upvotes':
        			$upvotes = count( get_post_meta( $post->ID, 'upvote' ) );
        			echo $upvotes;
        			break;
        		case 'downvotes':
        			$downvotes = count( get_post_meta( $post->ID, 'downvote' ) );
        			echo $downvotes;
        			break;
        	}
        }

    The edit.php page shows the upvotes/downvotes columns as fat, unsortable columns on the right hand side. I’d like to do the following:

    • Specify column width
    • Specify column order
    • Make columns sortable

    What’s the best way to do this?

    [Cross posted from stack overflow]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter cynicaloptimist

    (@cynicaloptimist)

    I managed to find a solution to the sorting problem at http://scribu.net/wordpress/custom-sortable-columns.html. An important caveat is that the ‘meta_key’ member of the $vars[] array is referring to a specific post_meta value in the database, which is only obvious in retrospect. It didn’t work at first with my code since I wasn’t storing the total number of votes in post_meta, just each individual vota (and its associated IP).

    I’m still trying to figure out how to make the columns appear more nicely. Might be a stylesheet problem.

    Thread Starter cynicaloptimist

    (@cynicaloptimist)

    Update 2: The columns were easily style with the stylesheet, as expected. I never found a way to make my own columns appear to the left of the WordPress core columns, and I believe this is intended behavior.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How do I format custom columns in the list view for custom post types?’ is closed to new replies.