Created
November 16, 2012 10:06
-
-
Save anonymous/4086131 to your computer and use it in GitHub Desktop.
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
/* | |
$myArr: | |
array(3) { | |
["id"]=> array(3) { | |
[0]=> string(1) "9" | |
[1]=> string(1) "2" | |
[2]=> string(1) "8" | |
} | |
["title"]=> array(3) { | |
[0]=> string(6) "qweqwe" | |
[1]=> string(11) "Sample Page" | |
[2]=> string(4) "Test" | |
} | |
["url"]=> array(3) { | |
[0]=> string(13) "http://qweqwe" | |
[1]=> string(39) "http://sample-page/" | |
[2]=> string(16) "http://google.com" | |
} | |
} | |
*/ | |
foreach( $myArr as $arr ) { | |
/* | |
I'd like to be able to use echo $arr['url'] etc | |
All [0] belongs together like: [0] 9, [0] qweqwe and [0] http://qweqwe | |
Example: | |
echo $arr['title'] . ': ' . $arr['url']; | |
should output: | |
qweqwe: http://qweqwe | |
Sample Page: http://sample-page/ | |
Test: http://google.com | |
*/ | |
} | |
function get_menu_items( $menu_name ) { | |
if( !$menu_name ) | |
return false; | |
if( ( $locations = get_nav_menu_locations() ) && isset( $locations[$menu_name] ) ) { | |
$menu = wp_get_nav_menu_object( $locations[$menu_name] ); | |
$menu_items = wp_get_nav_menu_items( $menu->term_id ) ; | |
foreach ( (array) $menu_items as $key => $menu_item ) { | |
$output['id'][] = $menu_item->object_id; | |
$output['title'][] = $menu_item->title; | |
$output['url'][] = $menu_item->url; | |
} | |
return $output; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment