Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sample SQL file to return menu items for a post in WordPress 3.0
<?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
You can’t perform that action at this time.