Skip to content

#14439 fix: filter associated nav menu items by menu - #12956

Draft
skikken wants to merge 2 commits into
WordPress:trunkfrom
skikken:fix/14439-menu-specific-associated-items
Draft

#14439 fix: filter associated nav menu items by menu#12956
skikken wants to merge 2 commits into
WordPress:trunkfrom
skikken:fix/14439-menu-specific-associated-items

Conversation

@skikken

@skikken skikken commented Aug 10, 2026

Copy link
Copy Markdown

Changes:

  1. Adds a new optional $menu_id parameter (default 0, appended after $taxonomy so all existing calls are unaffected). When set, only menu items belonging to that menu are returned.
  2. Validates the menu ID up front: if a non-zero $menu_id does not correspond to an existing nav_menu term, the function returns an empty array. This covers the invalid-ID case from the 2015 refresh.
  3. Filters by the item's nav_menu term assignment (wp_get_post_terms()) inside the existing loop, so the query shape is unchanged and behavior for the existing object types is identical.

Backward compatibility is preserved: calls without $menu_id return items from all menus exactly as before, which the included unit test asserts explicitly.

Trac ticket: https://core.trac.wordpress.org/ticket/14439

Use of AI Tools

AI assistance: Yes
Tool(s): Claude
Model(s): Sonnet
Used for: Writing test cases


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

wp_get_associated_nav_menu_items() returned menu items for an object
from any menu. Add a $menu_id parameter to restrict results to a
specific menu, with validation that the menu exists.

Closes #14439
@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant