1

I'm trying create custom status called "Priority Order" when the product change status to "Priority Order" will automatically add post meta called _priority_list numeric based on how much orders set to priority orders, my questions is how to make default order list using meta _priority_list? here is my current code:

function filter_priority_orders() {
    global $pagenow;
    $qv = &$query->query_vars;

    if ( $pagenow == 'edit.php' && isset($qv['post_status']) && $qv['post_status'] == 'wc-priority-order' ) {            
        $query->set('meta_key', '_priority_list');
        $query->set('order_by', '_priority_list');
    }

    return $query;
}
add_filter( 'pre_get_posts', 'filter_priority_orders' );

Thanks in advance!

1

I've solved my problem myself, thanks

function filter_priority_orders($query) {
    global $pagenow;
    $qv = $query->query_vars;

    if ( $pagenow == 'edit.php' && 
        isset($qv['post_status']) && $qv['post_status'] == 'wc-priority-order' && 
        isset($qv['post_type']) && $qv['post_type'] == 'shop_order' ) 
        {            
        $query->set('meta_key', '_priority_list');
        $query->set('orderby', 'meta_value_num');
        $query->set('order', 'ASC' );
    }

    return $query;
}

add_filter( 'pre_get_posts', 'filter_priority_orders' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.