WordPress.org

Ready to get started?Download WordPress

Forums

Types - Custom Fields and Custom Post Types Management
View/sort by custom field in admin post list (4 posts)

  1. Eliot Akira
    Member
    Posted 1 year ago #

    Hello, I just started using Types today, and I love the concept. I'm also interested in integrating Views to allow me to do wonders. However, there is one feature which is missing in Types: the ability to view/sort custom fields as columns in the admin post list view.

    I've spent a few hours trying to implement this, and I see that many people have requested this feature. I finally managed it, so here is the code for everyone who is searching. Add this in your functions.php:

    //Add custom column
    add_filter('manage_edit-YOURPOSTTYPENAME_columns', 'my_columns_head');
    function my_columns_head($defaults) {
    $defaults['YOURCOLUMNNAME'] = 'YOURCOLUMNTITLE';
    return $defaults;
    }
    //Add rows data
    add_action( 'manage_YOURPOSTTYPENAME_posts_custom_column' , 'my_custom_column', 10, 2 );
    function my_custom_column($column, $post_id ){
    switch ( $column ) {
    case 'YOURCOLUMNNAME':
    echo get_post_meta( $post_id , 'wpcf-YOURCUSTOMFIELDNAME' , true );
    break;
    }
    }
    
    // Make these columns sortable
    function sortable_columns() {
      return array(
        'YOURCOLUMNNAME'      => 'YOURCOLUMNNAME'
      );
    }
    
    add_filter( "manage_edit-YOURPOSTTYPENAME_sortable_columns", "sortable_columns" );

    It would also be nice to be able to filter these fields from the drop-down menu above the post list. However, this will do for now..

    Please, if anyone involved in developing this plugin is reading this, a lot of people would appreciate this feature included. Thank you.

    http://wordpress.org/plugins/types/

  2. Eliot Akira
    Member
    Posted 1 year ago #

    And to delete an unwanted column such as 'date' which might be unnecessary for some custom post types:

    // Delete column
    
    function my_columns_filter( $columns ) {
        unset($columns['DELETECOLUMNNAME']);
        return $columns;
    }
    add_filter( 'manage_edit-YOURPOSTTYPENAME_columns', 'my_columns_filter', 10, 1 );
  3. Eliot Akira
    Member
    Posted 1 year ago #

    For anyone who would like to view/sort custom fields in the admin post list, I found this plugin today that would have solved the issue without having to code it:

    http://wordpress.org/plugins/codepress-admin-columns/

  4. PowZone
    Member
    Posted 4 months ago #

    Thank you Akira!!

    Wonderful post ;)

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic