Skip to content

Instantly share code, notes, and snippets.

@Strae
Created August 26, 2016 10:24
Show Gist options
  • Save Strae/7b44e8b9c4dcff60553c694953d8b104 to your computer and use it in GitHub Desktop.
Save Strae/7b44e8b9c4dcff60553c694953d8b104 to your computer and use it in GitHub Desktop.
Wordpress menu sql
SELECT
p.ID,
m.meta_value,
md.post_author,
wp_users.user_nicename,
p.post_parent,
p.menu_order,
md.post_title
FROM
wp_posts AS p
INNER JOIN wp_postmeta AS m ON m.post_id = p.ID
INNER JOIN wp_posts AS md ON md.ID = m.meta_value AND m.meta_value = md.ID
INNER JOIN wp_users ON md.post_author = wp_users.ID
WHERE
p.menu_order > 0 AND
p.post_type = 'nav_menu_item' AND
m.meta_key = '_menu_item_object_id'
ORDER BY
p.menu_order ASC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment