michaeluno / admin-page-framework

Facilitates WordPress plugin and theme development.
http://admin-page-framework.michaeluno.jp/
Other
340 stars 71 forks source link

question: sortable_columns_{post type slug} orderby? #84

Closed patrickf0 closed 9 years ago

patrickf0 commented 10 years ago

Hi, how do I set the orderby-algorithm for a sortable column?

michaeluno commented 10 years ago

I'm not sure exactly what you are asking. Maybe does this page help? http://wordpress.stackexchange.com/questions/45/how-to-sort-the-admin-area-of-a-wordpress-custom-post-type-by-a-custom-field

patrickf0 commented 10 years ago

Well I´ve got some sortable columns for my custom taxonomy.

public function sortable_columns_TicketTax( $aSortableHeaderColumns ) { // sortable_columns_{post type slug}

    $column = array( 'name' => 'name', 'sort' => 'ticket_cat_sort', 'posts' => 'count');

    return $column;

}

public function cell_TicketTax( $sCellHTML, $sColumnSlug, $iTermID ) {  // cell_{extended class name}

    $aOptions = get_option( 'TicketTax' );

    switch ( $sColumnSlug ) {
        case 'sort':
            echo '<span style="text-align:center;">' . $aOptions[ $iTermID ][ 'ticket_cat_sort' ] . '</span>';
            break;
    }

}

But when I sort this column the orderby does not work properly. How do I set the algorithm for the $aOptions[ $iTermID ][ 'ticket_cat_sort' ] orderby?

michaeluno commented 10 years ago

Is it for edit-tags.php or edit.php?

patrickf0 commented 10 years ago

edit-tags

michaeluno commented 10 years ago

Okay I committed an example of implementing customizing the sort algorithm of a custom column of taxonomy term listing table. It's already available in the master branch: https://github.com/michaeluno/admin-page-framework/archive/master.zip

The bottom line is that you have to code the part that sorts items as the framework cannot know what you want to do with them.

The steps that I did in the example are:

  1. set up a callback with the get_terms hook.
  2. in the callback method, check if the method/function is triggered for the term listing table and for sorting a column.
  3. In the callback method, sort the passed array holding the term objects and return it.

Hope it helps!