Log1x / navi

A developer-friendly alternative to the WordPress NavWalker.
https://github.com/Log1x/navi
MIT License
315 stars 30 forks source link

Parent slug isn't correct #61

Closed jccbbb closed 1 year ago

jccbbb commented 1 year ago

Evening 🤗

What I am trying to do: To get the parent of a child in the menus post ID.

I am creating a top level parent of the menu that only has custom links (with anchor tags) as child(s) like below.

Menu with child item

The about us page has the post ID 214 (seen in the URL): url-slug

However when I do a <?php dump( $child); ?> from the code do I get a completely different value (215): wrong-value

{#2770 â–¼ +"active": false +"activeAncestor": false +"activeParent": false +"classes": false +"dbId": 291 +"description": false +"id": 291 +"label": "Custom link" +"objectId": "291" +"parent": "215" +"slug": "{hidden by me}" +"target": false +"title": false +"url": "#test" +"xfn": false +"children": [] }

Shouldn't not the parent: equal 214? Because I would need to get out this value from the child itself to be able to get it's parent permalink 😊 Is it something I am doing wrong or have misunderstood with the logic? I have used the objectId since its correct with the post ID for other stuff but when I am on a child and need to pick out the value from there the only reference is the parent but that value isn't correct.

PS: This is the dump for the parent itself (About us) before it continues down to the child. dump-of-parent {#2771 â–¼ +"active": false +"activeAncestor": false +"activeParent": false +"classes": false +"dbId": 215 +"description": false +"id": 215 +"label": "About us" +"objectId": "214" +"parent": false +"slug": "215" +"target": false +"title": false +"url": "http://localhost:8181/about-us/" +"xfn": false +"children": array:1 [â–¼ 291 => {#2770 â–¶} ] }

I also don't know if it is a similar error to what is happening for LucasDemea #58

Log1x commented 1 year ago

Thanks for the detailed report.

I assume there's something different happening with the nav attributes. I'm extremely swamped right now but I'll try to look into it when I can if somebody else doesn't beat me to it.

jccbbb commented 1 year ago

Thanks for the detailed report.

I assume there's something different happening with the nav attributes. I'm extremely swamped right now but I'll try to look into it when I can if somebody else doesn't beat me to it.

Thank you for getting back so quickly Brandon 😊 I would love to help you out but my current code/PHP knowledge isn't at that level that I know really where to start and debug it unfortunately.

Anyhow, if you ever have time in the future, would it be highly appreciated if you had time to take a look on it 😊

jccbbb commented 1 year ago

Hello @Log1x ,

Have you been able to check on this? 😋 I'm currently blocked in a project where I really need to get the correct parent ID slug 😊

Log1x commented 1 year ago

Not yet. I'll try to get a reproducible environment going this weekend. Sorry about the delay.

jccbbb commented 1 year ago

Not yet. I'll try to get a reproducible environment going this weekend. Sorry about the delay.

No worries mate! I know life can be hectic 🤗

jccbbb commented 1 year ago

Hey @Log1x ,

Have you been able to find time to look on this? 🤗

jccbbb commented 1 year ago

Hey @Log1x,

I'm a little bit locked with a delivery to my client since I can't get the correct ID of a parent of a child. Are you able to look into this? I can pay if needed 😊

Log1x commented 1 year ago

When Navi gives you a parent by default, it typically represents the ID of the parent menu item its self.

I added parentObjectId in v2.0.4 that should let you get the ID of whatever you have the parent menu item assigned to (post, term, etc.)

jccbbb commented 1 year ago

When Navi gives you a parent by default, it typically represents the ID of the parent menu item its self.

I added parentObjectId in v2.0.4 that should let you get the ID of whatever you have the parent menu item assigned to (post, term, etc.)

Thank you @Log1x! It works perfectly now 😊