Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * first paste: http://pastebin.com/wuSwHjjg
- */
- //enable newly added column ordering
- add_filter( 'manage_edit-post_sortable_columns', 'dct_table_sorting' ); //use manage_edit-{post_type}_sortable_columns for custom post type
- function dct_table_sorting( $columns ) {
- $columns['column1'] = 'column1';
- $columns['column2'] = 'column2';
- return $columns;
- }
- add_filter( 'request', 'dct_column1_orderby' );
- function dct_column1_orderby( $vars ) {
- if ( isset( $vars['orderby'] ) && 'column1' == $vars['orderby'] ) {
- $vars = array_merge( $vars, array(
- 'meta_key' => 'column1_meta_key',
- 'orderby' => 'meta_value'
- ) );
- }
- return $vars;
- }
- add_filter( 'request', 'dct_column2_orderby' );
- function dct_column2_orderby( $vars ) {
- if ( isset( $vars['orderby'] ) && 'column2' == $vars['orderby'] ) {
- $vars = array_merge( $vars, array(
- 'meta_key' => 'column2_meta_key',
- 'orderby' => 'meta_value'
- ) );
- }
- return $vars;
- }
- /*
- *re-arranging table columns
- *lets add these two columns before date (date is the last column of the list by default)
- *if we want to do this, then we need to add following codes inside function "dct_table_head" (see paste: http://pastebin.com/wuSwHjjg) before returning.
- */
- $key = 'date'; //name of the "date" column key
- $offset = array_search($key, array_keys($defaults));
- $result = array_merge
- (
- array_slice($defaults, 0, $offset),
- array('column1' => 'Column1', 'column2' => 'Column2'),
- array_slice($defaults, $offset, null)
- );
- //we will then return $result, instead of $defaults
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement