Support

Account

Home Forums Backend Issues (wp-admin) Sorting custom columns in the WordPress Admin

Solved

Sorting custom columns in the WordPress Admin

  • I have successfully added a custom column to the WordPress back-end, but can’t get sorting to register. The page below was helpful.

    http://www.elliotcondon.com/advanced-custom-fields-admin-custom-columns/

    The ‘type’ field shows on the ‘press’ post-type but without sorting. No error is returned.

    Here is my code below:

    // ADD NEW COLUMN
    function ST4_columns_head($defaults) {
    	$defaults['type'] = 'Type';
    	$defaults['featured_image'] = 'Featured Image';
    
    	return $defaults;
    }
    
    // SHOW THE FEATURED IMAGE
    function ST4_columns_content($column_name, $post_ID) {
    	if ($column_name == 'featured_image') {
    		echo get_the_post_thumbnail( $post_ID, 'tiny', $attr );
    	}
    	
    	if ($column_name == 'type') {
    		echo get_field( "type", $post_ID );
    	}
    }
    
    add_filter('manage_press_posts_columns', 'ST4_columns_head');
    add_action('manage_press_posts_custom_column', 'ST4_columns_content', 10, 2);
    
    //make the new column sortable
    function my_press_sortable_columns( $columns ) {
    	$columns['type'] = 'type';
    	return $columns;
    }
    add_filter( 'manage_press_sortable_columns', 'my_press_sortable_columns' );
    • Elliot

    • December 3, 2013 at 2:04 pm

    Hi @michael.levy

    Although ACF does allow you to save and store data, this ‘sorting’ of the wp-admin columns is not really something I can help you with, as it is more a common WP question, than one which is related to an ACF issue.

    There are many tutes on google for this kind of thing, and there is even a plugins called “CodePress Admin Columns” which automates the whole thing for you!

    Thanks
    E

  • Yes CodePress Admin Columns is pretty cool. Though I avoid plugins that should be easily addressed with a few lines of code in theme function file. One less thing to break.

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

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.