I have custom meta fields,
collection_date on WooCommerce orders.
I actually have various fields with the same data, in various formats (
D d/m/Y) any of which may be useful.
I'd like to list (in an admin page;
is_admin() && $query->is_main_query()) all invalid orders - those where the delivery date or collection date is present and is prior to the
I can't see how to create
meta_querys which compare a postmeta value with a post value, do I need to use a
Apologies if I haven't explained this well.
edit: The following MySQL query fetches the correct posts:
SELECT p.ID, p.post_date, pm.meta_value, pm.meta_key FROM wp_postmeta pm LEFT JOIN wp_posts p ON pm.post_id = p.ID WHERE pm.meta_key = '_delivery_date_ymd' AND pm.meta_value != '' AND pm.meta_value < p.post_date
Similar, but unanswered question: How can I create a WP_Query that returns posts where one meta_value <= another meta_value
*- This occurs when WooCommerce Subscriptions create renewal orders and the postmeta is copied verbatim.