[wp-hackers] Retreive menu item permalink
Lox
lox.dev at knc.nc
Mon Jun 21 00:29:25 UTC 2010
2010/6/21 Mike Schinkel <mikeschinkel at newclarity.net>:
> Sounds like you've worked on something very similar to something I worked on recently. Based on your description though I'm not sure how you are relating your custom post type to your menu item? In my case I created a custom field in postmeta for the custom post type and stored the menu ID in it for the post of post type "nav_menu_item." Is that how you did it, or something else? Maybe a little more specific details of what you are trying to accomplish would help us help you?
Concept is simple. A custom post type is called "Featured page". For
each I can add a title, a descriptive text, a secondary title, the
feature image, and the menu item to point to, on click. This last part
is done with two combo boxes, first u choose the menu in first one
then the second one get populated with the selected menu's items using
ajax. There u select the menu item. Both menu id and menu item are
stored for each "features page" custom post.
I then retreive them on home page and animate them using javascript.
When I retreive them, I make use of wordpress loop.
So the problem is to retreive a menu_item url from a menu_item's ID. I
can do it looping throught menu_items but I find that looping this way
for every "feature page" is ressource consuming:
function fp_get_menu_item ($menuId, $itemId) {
$menu = wp_get_nav_menu_object( $menuId );
if ( $menu && ! is_wp_error($menu) && !isset($menu_items) )
$menu_items = wp_get_nav_menu_items( $menu->term_id );
else return false;
foreach ($menu_items as $item) {
echo $item->ID . ' '. $itemId; echo "\n";
if($item->ID === (int)$itemId) return $item;
}
return false;
}
--
Lox
lox.dev at knc.nc
More information about the wp-hackers
mailing list