Created
July 28, 2010 01:57
-
-
Save mikeschinkel/493178 to your computer and use it in GitHub Desktop.
Sample SQL file to return menu items for a post in WordPress 3.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include "wp-load.php"; | |
$post_id = $_GET['post']; | |
$menu_id = $_GET['menu']; | |
global $wpdb; | |
$result = $wpdb->get_results($wpdb->prepare("SELECT t.term_id as menu_id, | |
t.name AS menu_name, | |
mi.ID AS menu_item_id, | |
mi.post_title AS menu_title, | |
p.post_title, | |
mm.* | |
FROM wp_terms t INNER JOIN wp_term_taxonomy tt ON t.term_id = tt.term_id | |
INNER JOIN wp_term_relationships tr ON tt.term_taxonomy_id = tr.term_taxonomy_id | |
INNER JOIN wp_posts mi ON tr.object_id = mi.ID | |
INNER JOIN wp_postmeta mm ON mm.post_id=mi.ID | |
INNER JOIN wp_posts p ON p.ID=mm.meta_value | |
WHERE | |
mi.post_type='nav_menu_item' AND | |
mm.meta_key='_menu_item_object_id' AND | |
t.term_id=$menu_id AND | |
p.ID=$post_id | |
")); | |
header('Content-type:text/plain'); | |
print_r($result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment