• Resolved crslz

    (@crslz)


    I’m trying to make the expiry_date column sortable.

    I guess the problem has something to do with an incorrect meta key value.

    function my_sortable_expiry_date_column( $columns ) {
        $columns['expiry_date'] = 'expiry_date';
    
        //To make a column 'un-sortable' remove it from the array
        //unset($columns['date']);
    
        return $columns;
    }
    add_filter( 'manage_edit-shop_coupon_sortable_columns', 'my_sortable_expiry_date_column' );
    function my_expiry_date_orderby( $query ) {
        if( ! is_admin() )
            return;
    
        $orderby = $query->get( 'orderby');
    
        if($orderby == 'expiry_date') {
            $query->set('meta_key','expiry_date');
            $query->set('orderby','meta_value_num');
        }
    }
    add_action( 'pre_get_posts', 'my_expiry_date_orderby' );

    How can I find the correct meta_key? How do I orberby ‘date types’ column?

    Thnx!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi there,

    You’ve done a great job here!

    The one thing you’ve missed is that the meta_key column in the wp_postmeta table doesn’t list the Expiration Date as expiry_date.

    You’d instead want to change this to date_expires.

    So your line would be:

    $query->set('meta_key','date_expires');

    I just tried this out and it works perfectly.

    Let us know if you have any further questions!

    Thank you,
    Joey

    Thread Starter crslz

    (@crslz)

    problem SOLVED, thanks!!

    Thanks for including this!
    We appreciate the work you’ve done here. ??

    Thank you,
    Joey

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Shop_coupon: make the expiry date column sortable’ is closed to new replies.