Skip to content

Instantly share code, notes, and snippets.

@barryhughes
Created July 6, 2016 21:38
Show Gist options
  • Select an option

  • Save barryhughes/846443217379309153d3006a8a509ca2 to your computer and use it in GitHub Desktop.

Select an option

Save barryhughes/846443217379309153d3006a8a509ca2 to your computer and use it in GitHub Desktop.
-- Get the missing order post IDs
SELECT post_id as missing_order,
-- "Estimate" the date by looking at the next available post's date
(
SELECT post_date
FROM wp_posts
WHERE ID > post_id
ORDER BY ID ASC
LIMIT 1
) as nearest_date
FROM wp_postmeta
LEFT JOIN wp_posts
ON wp_posts.ID = wp_postmeta.post_id
-- Order posts all have a _payment_method meta field
-- (indicating PayPal or Stripe, etc)
WHERE meta_key = '_payment_method'
AND ID IS NULL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment