Skip to content

Instantly share code, notes, and snippets.

@dgowrie
Last active December 13, 2018 04:16
Show Gist options
  • Select an option

  • Save dgowrie/ebde7a89fd3d42bc1837818a0c6b78fd to your computer and use it in GitHub Desktop.

Select an option

Save dgowrie/ebde7a89fd3d42bc1837818a0c6b78fd to your computer and use it in GitHub Desktop.
SQL queries for WordPress

Just a collection of SQL queries I find useful in WordPress management

SELECT P.ID, P.post_title, M.meta_key, M.meta_value
FROM wp_posts AS P
JOIN wp_postmeta AS M ON P.ID = M.post_id
AND M.meta_key = 'CUSTOM_FIELD'
WHERE P.post_type = 'products'
order by P.ID asc
SELECT P.ID, P.post_title, M.meta_key, M.meta_value
FROM wp_posts AS P
INNER JOIN wp_postmeta AS M ON M.post_id = P.ID
WHERE P.post_type = 'page' and P.post_status = 'publish' and M.meta_value = 'TEMPLATE_PATH/FILENAME.php'
ORDER BY post_title, meta_key
SELECT P.ID, P.post_title
FROM wp_posts AS P
WHERE P.post_type = 'products' and P.post_status = 'publish'
ORDER BY post_title
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment