I'm a bit rusty on the WordPress since version 5.9 but I can see that they've added Menus to the REST API and we can use new get methods in: wp.data.select("core")
.
I'm trying to get the menu items from a menu called 'legal', which has the ID 449. How do we use these new functions to get those menu items for use in custom blocks?
.getMenu(449)
Returns the legal menu object not including any menu items/links ???
{
"id": 449,
"description": "",
"name": "Legal",
"slug": "legal",
"meta": [],
"locations": [
"legal_menu"
],
"auto_add": false,
"_links": {
"self": [
{
"href": "http://example.com/wp-json/wp/v2/menus/449"
}
],
"collection": [
{
"href": "http://example.com/wp-json/wp/v2/menus"
}
],
"about": [
{
"href": "http://example.com/wp-json/wp/v2/taxonomies/nav_menu"
}
],
"wp:post_type": [
{
"href": "http://example.com/wp-json/wp/v2/menu-items?menus=449"
}
],
"wp:menu-location": [
{
"embeddable": true,
"href": "http://example.com/wp-json/wp/v2/menu-locations/legal_menu"
}
],
"curies": [
{
"name": "wp",
"href": "https://api.w.org/{rel}",
"templated": true
}
]
}
}
.getMenuItem()
No idea how to use this ??
.getMenuItems()
No idea how to use this ??
Can anyone help to fill in the gaps please?