Closed mgiraldo closed 6 years ago
ok so turns out the reason is that if the menu item is a page
, the post_name
is the page ID whereas if I make a “Custom Link” and point it to the corresponding /wp-json/wp/v2/pages/ID
link then the post_name
is the slug.
Hi, I'm using the wp_get_nav_menu_items Wordpress function. As you said, if the page hasn't got a slug it will return its id instead of its slug.
but the pages do have slugs:
or is there another field somewhere that i'm not adding?
As you can see in wp-rest-api-v2-menus.php on line 36, I simply populate the items attribute using wp_get_nav_menu_items function, that is a standard Wordpress function. I don't know the reason, but it work in this way. You can use /wp-json/wp/v2/pages/:object_id endpoint to get page's data and get your slug.
So sad. Can't generate menus with correct urls in SPA. The best what I can get is the url. And that url of course is my rest api endpoint :( :ambulance:
i am using this plugin with wp
page
types. menus are created properly but at some point thepost_name
for each items went from being theslug
to theid
. eg: frompost_name: "about-us"
topost_name: "6893"
. the logic in the app requires it to be the slug. old pages still show the slug but any new pages i create appear in the menu with their id. any idea what could have gone wrong?