Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Feb 2, 2026

Users need to retrieve individual menu item details (particularly menu_item_parent IDs) without listing all items and parsing output. Current workaround requires wp menu item list <menu> --fields=... | grep | awk.

Changes

  • Menu_Item_Command.php: Added get() method following wp term get pattern

    • Accepts <db-id> as required parameter
    • Validates post type is nav_menu_item (rejects regular posts)
    • Maps menu_orderposition and urllink for consistency with list command
    • Supports --field, --fields, and --format options
  • composer.json: Registered menu item get command

  • menu-item.feature: Added test scenario covering table/JSON/CSV formats and error cases

Usage

# Get parent menu item ID for hierarchical menu construction
$ wp menu item get 45 --field=menu_item_parent
12

# Get all details in JSON for programmatic parsing
$ wp menu item get 45 --format=json
{"db_id":45,"type":"custom","title":"WordPress","link":"https://wordpress.org","position":1,"menu_item_parent":12}

# Use in scripts to create child items
PARENT_ID=$(wp menu item list my-menu --format=ids | head -1)
wp menu item add-custom my-menu "Child" http://example.com --parent-id=$PARENT_ID

All available fields match those in wp menu item list: db_id, type, title, link, position, menu_item_parent, object_id, object, type_label, target, attr_title, description, classes, xfn.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • example.com
    • Triggering command: /usr/bin/php /usr/bin/php /home/REDACTED/work/entity-command/entity-command/vendor/wp-cli/wp-cli/bin/../php/boot-fs.php core install --url=REDACTED --title=WP CLI Site --admin_user=admin [email protected] --admin_password=password1 --skip-email ./tests/Compat/WP_Block_ProcessorTest.php git k/en�� -a --no-color /home/REDACTED/.dotnet/tools/git -v (dns block)
    • Triggering command: /usr/bin/php /usr/bin/php /home/REDACTED/work/entity-command/entity-command/vendor/wp-cli/wp-cli/bin/../php/boot-fs.php core install --url=REDACTED --title=WP CLI Site --admin_user=admin [email protected] --admin_password=password1 --skip-email --user=wp_cli_tefeatures/menu-item.feature sh -cli�� term url cal/bin/sh 2 (dns block)
    • Triggering command: /usr/bin/php /usr/bin/php /home/REDACTED/work/entity-command/entity-command/vendor/wp-cli/wp-cli/bin/../php/boot-fs.php core install --url=REDACTED --title=WP CLI Site --admin_user=admin [email protected] --admin_password=password1 --skip-email ordpress.org ls vend�� /var/lib/waagent sh k/entity-command/entity-command/vendor/bin/sh term arent ndor/bin/sh sh (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>WP CLI - Menu Item Get Command</issue_title>
<issue_description>Hi guys,

Could you consider to improve wp menu item commands with get method?

I have the problem to get some information of existing menu items for example ID. I try dynamically to add new items as child elements but I can't get parent menu item ID. At this moment we have options to list all menu items and here I can see menu item ID

wp menu item list main-menu

but if I want to create a simple program to collect menu items information and to add new items in predefined places, then I can't do that. Thanks for your time

Best regards,
Nenad</issue_description>

Comments on the Issue (you are @copilot in this section)

@schlessera @NenadObradovic If you want to retrieve the parent menu item ID, you can do this by adding the field `menu_item_parent` to the displayed fields: ``` wp menu item list main-menu --fields=db_id,title,menu_parent_item ``` With the above, for example, you can `grep` for a specific menu item title, and then use something like `awk` to retrieve the parent menu item ID.

Does that provide what you need, or are you thinking of something else specifically?</comment_new>


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Add get method for WP CLI menu item commands Add wp menu item get command Feb 2, 2026
Copilot AI requested a review from swissspidy February 2, 2026 18:44
@github-actions github-actions bot added command:menu-item Related to 'menu item' command command:menu-item-add-custom Related to 'menu item add-custom' command command:menu-item-list Related to 'menu item list' command command:menu-item-update Related to 'menu item update' command labels Feb 2, 2026
@codecov
Copy link

codecov bot commented Feb 2, 2026

Codecov Report

❌ Patch coverage is 0% with 30 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/Menu_Item_Command.php 0.00% 30 Missing ⚠️

📢 Thoughts on this report? Let us know!

This comment was marked as resolved.

@swissspidy swissspidy marked this pull request as ready for review February 3, 2026 14:45
@swissspidy swissspidy requested a review from a team as a code owner February 3, 2026 14:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

command:menu-item Related to 'menu item' command command:menu-item-add-custom Related to 'menu item add-custom' command command:menu-item-list Related to 'menu item list' command command:menu-item-update Related to 'menu item update' command

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WP CLI - Menu Item Get Command

2 participants