我想要一个mysql查询来获取挂单状态的所有订单。有人知道怎么做。
我在wordpress网站上使用woocommerce,但我只想要mysql查询而不是wordpress功能。
由于
答案 0 :(得分:1)
您确实应该使用内置数据库函数,因为它符合Wordpress coding standards。
您可以查看WC_Query课程。
或者您可以尝试类似下面的内容。您需要将元键更改为他们正在使用的元键。此外,元值可能与挂起的不同,post_type可能与'shop_order'不同。
$pending = new WP_Query(
array(
'post_type' => array('shop_order'),
'meta_query' => array(
array(
'key' => 'status',
'value' => array('pending'),
)
)
)
);
以下是关于如何对woocommerce订单进行元查询的one example。
答案 1 :(得分:0)
好的,这是一个奇怪的问题,但我通过简单地使用自定义查询来修复它。以某种方式添加'post_status' => 'wc-pending'
实际上并未更改查询,但如果我使用pending
,则查询会更改。
所以我所做的就是使用该自定义查询并将待处理修改为wc-pending
。
答案 2 :(得分:-1)
我花了整个周末来处理查询,结果如下:
select
nombre,apellido,direccion,direccion2,codigo,poblacion,provincia,correo, telefono
from (
select
(select meta_value from wp_postmeta pm1 where p.ID = pm1.post_id and meta_key = "_billing_first_name") as nombre,
(select meta_value from wp_postmeta pm1 where p.ID = pm1.post_id and meta_key = "_billing_last_name") as apellido,
(select meta_value from wp_postmeta pm1 where p.ID = pm1.post_id and meta_key = "_billing_address_1") as direccion,
(select meta_value from wp_postmeta pm1 where p.ID = pm1.post_id and meta_key = "_billing_address_2") as direccion2,
(select meta_value from wp_postmeta pm1 where p.ID = pm1.post_id and meta_key = "_customer_user") as codigo,
(select meta_value from wp_postmeta pm1 where p.ID = pm1.post_id and meta_key = "_billing_city") as poblacion,
(select meta_value from wp_postmeta pm1 where p.ID = pm1.post_id and meta_key = "_billing_state") as provincia,
(select meta_value from wp_postmeta pm1 where p.ID = pm1.post_id and meta_key = "_billing_email") as correo,
(select meta_value from wp_postmeta pm1 where p.ID = pm1.post_id and meta_key = "_billing_phone") as telefono
from
wp_posts AS p
WHERE post_type = "shop_order" and id in (SELECT object_id
FROM wp_posts
LEFT OUTER JOIN wp_term_relationships ON wp_posts.ID=wp_term_relationships.object_id
WHERE post_type = "shop_order"
AND term_taxonomy_id=9
)
) A