最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - How to display SQL query that ran in WC_Order_Query?

programmeradmin3浏览0评论

Using WP_Query you can do: (new WP_Query($arguments))->request to get the raw SQL code that was executed.

But how can you do this with WooCommerces WC_Order_Query or wc_get_orders?

Using WP_Query you can do: (new WP_Query($arguments))->request to get the raw SQL code that was executed.

But how can you do this with WooCommerces WC_Order_Query or wc_get_orders?

Share Improve this question asked Jan 27, 2020 at 11:26 FooBarFooBar 4441 gold badge8 silver badges23 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

WC_Order_Query does not store a record of the SQL it generated, or the WP_Query that it used internally. So it's not possible to get the information you need from WC_Order_Query directly.

You could try using $wpdb->last_query immediately after using the class or function, but the last query more than likely isn't the one you're actually looking for:

global $wpdb;

$orders = wc_get_orders();

$query = $wpdb->last_query;

Your best bet is to use a tool like Query Monitor, which will allow you to see all the SQL queries run during a page load. You could use this to inspect your query.

发布评论

评论列表(0)

  1. 暂无评论