Sorting not working properly
-
Hi,
Can anyone help me?
We have 3 sites, I am using this code to sort a column on woocommerce admin page. It is working fine on 1 of our website but it is not working properly on the other 2.
What could be the possible cause?
Here is the code:
// Make existing “Printed Date” column sortable on admin orders list
add_filter( “manage_edit-shop_order_sortable_columns”, ‘shop_order_column_meta_field_sortable’ );
function shop_order_column_meta_field_sortable( $columns )
{
$meta_key = ‘_date_printed’;
return wp_parse_args( array(‘_date_printed’ => $meta_key), $columns );
}
// Make “Printed Date” sorting properly (by numerical values)
add_action(‘pre_get_posts’, ‘shop_order_column_meta_field_sortable_orderby’ );
function shop_order_column_meta_field_sortable_orderby( $query ) {
global $pagenow;
// Targeting WooCommerce admin orders list only
if ( ‘edit.php’ === $pagenow && isset($_GET[‘post_type’]) && ‘shop_order’ === $_GET[‘post_type’] ){
$orderby = $query->get( ‘orderby’);
$meta_key = ‘_date_printed’;
if (‘_date_printed’ === $orderby){
$query->set(‘meta_key’, $meta_key);
$query->set(‘orderby’, ‘_date_printed’); // Or using ‘meta_value’
}
}
}
- The topic ‘Sorting not working properly’ is closed to new replies.