Custom Field Date Sorting not Working
Using WordPress 4.8.2 with Admin Columns Pro version 4.0.10.
We have a custom post type called “items” that has a custom field called “date” which is (as you guessed!) a date field. All the custom fields on the site are created manually in the theme (not using ACF). Our “Item” post type is using your Admin Columns plugin to give our users the ability to sort the posts on the backend by custom fields. We originally setup the site to be able to sort by the date inputed in the custom field, and it worked great on versions < 4.0 using this code:
/** Inline Edit for Admin Columns **/
function cf_set_custom_field_date_store_format( $value, $column, $id ){
$column_type = 'column-meta';
$custom_field_type = 'date';
if ( $column_type == $column->get_type() && $custom_field_type == $column->get_field_type() ) {
$value = date('Y-m-d', strtotime($value));
}
return $value;
}
add_filter( 'cac/inline-edit/ajax-column-save/value', 'cf_set_custom_field_date_store_format', 10, 3 );
Once we updated the plugin to version 4.0.3 (or 4.0.4… can’t remember exactly) back in June the column sorting stopped working for us. Our first attempt to fix this was to update the above code according to the 4.0 docs:
/** Inline Edit for Admin Columns **/
function cf_set_custom_field_date_store_format( $value, $column, $id ){
$column_type = 'column-meta';
$custom_field_type = 'date';
if ( $column_type == $column->get_type() && $custom_field_type == $column->get_field_type() ) {
$value = date('Y-m-d', strtotime($value));
}
return $value;
}
add_filter( 'acp/editing/save_value', 'cf_set_custom_field_date_store_format', 10, 3 );
This, however, didn’t fix the issue and we’re still stumped on what’s causing the problem. Any help or pointers as to how we can get the custom field date sorting to start working again for our custom post type?
You must be logged in to reply to this topic.