Php 使用wc_get_orders()orderby参数作为Web应用程序中的自定义字段
我有一个元字段,其中输入了时间,例如12:0,0 13:03,01:00。。。我想按此字段“账单”排序 目前,我已经在下面的代码中添加了orderby和order参数,但是它们被忽略了 如何在元字段中按时间排序Php 使用wc_get_orders()orderby参数作为Web应用程序中的自定义字段,php,wordpress,sorting,woocommerce,orders,Php,Wordpress,Sorting,Woocommerce,Orders,我有一个元字段,其中输入了时间,例如12:0,0 13:03,01:00。。。我想按此字段“账单”排序 目前,我已经在下面的代码中添加了orderby和order参数,但是它们被忽略了 如何在元字段中按时间排序 $args = array( 'orderby' => 'billing_eta', //has no effect as its a meta field 'order' => 'DESC', 'status' => 'compl
$args = array(
'orderby' => 'billing_eta', //has no effect as its a meta field
'order' => 'DESC',
'status' => 'completed', // Accepts a string: one of 'pending', 'processing', 'on-hold', 'completed', 'refunded, 'failed', 'cancelled', or a custom order status.
'meta_key' => 'billing_date', // Postmeta key field
'meta_value' => $ppr_arrival_date, // Postmeta value field
'meta_compare' => '==', // Possible values are ‘==’, ‘!=’, ‘>’, ‘>=’, ‘<‘, ‘<=’, ‘LIKE’, ‘NOT LIKE’, ‘IN’, ‘NOT IN’, ‘BETWEEN’, ‘NOT BETWEEN’, ‘EXISTS’ (only in WP >= 3.5), and ‘NOT EXISTS’ (also only in WP >= 3.5). Values ‘REGEXP’, ‘NOT REGEXP’ and ‘RLIKE’ were added in WordPress 3.7. Default value is ‘=’.
);
$orders = wc_get_orders( $args );
在meta_查询中需要两个meta元素,因此:
$args = array(
'status' => 'completed',
'orderby' => 'eta',
'order' => 'ASC',
'meta_query' => array(
'arrival_date' => array(
'key' => 'billing_date',
'value' => $ppr_arrival_date,
'compare' => '='
),
'eta' => array(
'key' => 'billing_eta',
'compare' => 'EXISTS',
'type' => 'TIME'
),
)
);
您确定元键
billing\u date
不是以下划线开头的,比如\u billing\u date
(请在wp\u postmeta
数据库表中进行检查)。我已经用这两种方法尝试过了。我发现在结账日,无论是有工作还是没有工作,都只收到了原始值的订单,而不是在管理面板中更改的订单。一、 因此,假设这一时间是相同的(计费时间)。是的,所有自定义字段都应该是相同的…奇怪的是,它是不同的。。。但不管怎样,我还是不能按预定时间或预定时间订购。有什么想法吗?是的,它就像a和orderby参数一样工作。
$args = array(
'status' => 'completed',
'orderby' => 'eta',
'order' => 'ASC',
'meta_query' => array(
'arrival_date' => array(
'key' => 'billing_date',
'value' => $ppr_arrival_date,
'compare' => '='
),
'eta' => array(
'key' => 'billing_eta',
'compare' => 'EXISTS',
'type' => 'TIME'
),
)
);