“Last Update” Custom Column Sorting
-
I have a custom post type name “Organization” in which there is a field called “Last Update”. I save data of this field using
update_post_meta( $company_id, 'profile_updated_on', current_time( 'timestamp', 0 ) );
Now in custom post type admin dashboard i’m not able to sort this “Last Updated” field. I used this below code for sorting which is not sorting correctly.
// Add the custom columns to the organization post type: add_filter( 'manage_edit-organization_columns', 'set_custom_edit_organization_columns' ); function set_custom_edit_organization_columns($columns) { $columns['profile_updated_on'] = __( 'Last Updated', 'cthe' ); return $columns; } // Add the data to the custom columns for the organization post type: add_action( 'manage_organization_posts_custom_column' , 'custom_organization_column', 10, 2 ); function custom_organization_column( $column_name, $post_id ) { if('profile_updated_on' != $column_name) return; $profile_updated_on_timestamp = get_post_meta( $post_id , 'profile_updated_on' , true ); //echo date_i18n($profile_updated_on); echo get_date_from_gmt( date( 'Y-m-d ', $profile_updated_on_timestamp ), 'F j, Y' ); } function your_columns_head($defaults) { $new = array(); $updated_by = $defaults['profile_updated_on']; // save the tags column foreach($defaults as $key=>$value) { if($key=='date') { // when we find the date column $new['profile_updated_on'] = $updated_by; // put the tags column before it } $new[$key]=$value; } echo "<pre>"; print_r($new); return $new; } add_filter('manage_organization_posts_columns', 'your_columns_head'); function set_custom_organization_sortable_columns( $columns ) { $columns['profile_updated_on'] = 'profile_updated_on'; //To make a column 'un-sortable' remove it from the array //unset($columns['title']); return $columns; } add_filter( 'manage_edit-organization_sortable_columns', 'set_custom_organization_sortable_columns' );
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘“Last Update” Custom Column Sorting’ is closed to new replies.