我正在使用以下sql查询来获取其名称的自定义菜单:
SELECT p2.post_title, p2.post_name, p2.guid
FROM wp_posts p1
INNER JOIN wp_term_relationships AS TR
ON TR.object_id = p1.ID
INNER JOIN wp_postmeta AS PM
ON pm.post_id = p1.ID
INNER JOIN wp_posts AS p2
ON p2.ID = PM.meta_value
WHERE p1.post_type = 'nav_menu_item'
AND TR.term_taxonomy_id = ( SELECT wp_terms.term_id FROM wp_terms WHERE wp_terms.slug = '$custom_menu')
AND pm.meta_key = '_menu_item_object_id'
ORDER BY p1.menu_order ASC
现在我在网站上使用WPML,需要通过语言代码获取此菜单。如何将其添加到此查询中?
提前感谢您对此的任何帮助!
答案 0 :(得分:0)
试试这个,对我有用。
SELECT p2.ID, p2.post_content, p2.post_title, p2.post_name, p2.guid, p1.post_parent
FROM wp_posts p1
INNER JOIN wp_term_relationships AS TR
ON TR.object_id = p1.ID
INNER JOIN wp_postmeta AS pm
ON pm.post_id = p1.ID
INNER JOIN wp_posts AS p2
ON p2.ID = pm.meta_value
WHERE p1.post_type = 'nav_menu_item'
AND TR.term_taxonomy_id = ( SELECT wp_term_taxonomy.term_taxonomy_id FROM wp_terms LEFT JOIN wp_term_taxonomy ON wp_terms.term_id=wp_term_taxonomy.term_id AND `taxonomy` = 'nav_menu' WHERE wp_terms.slug = '" . $this->real_escape_string($slug) . "')
AND pm.meta_key = '_menu_item_object_id'
ORDER BY p1.menu_order ASC