I've found this documentation about adding terms using WP CLI: https://developer.wordpress.org/cli/commands/menu/item/add-term/ and tried to find out how I can add an existing category to the main-menu, but no luck.

The documentation hasn't got an example of this one or isn't clear enough to me at the moment.

Hopefully anyone else did this one before and can tell me how to accomplish it. I've got now: (but this doesn't work)

wp menu item add-term main-menu category 1

Thanks in advance!

  • what WP version are you on? are you using a full site editing theme? Commented Jul 25, 2022 at 23:09
  • Latest, WP 6.0.1, WP-CLI 2.6.0. Just a Wordpress theme from the theme library, nothing special with builders Commented Jul 26, 2022 at 9:24
  • do a wp menu list to list all the registered menus and make sure you have the Main Menu registered as a menu. I just tested on a new WP instance with the twentytwentyone theme ( no full site editing ) with your exact CLI command: wp menu item add-term main-menu category 1 and it works Commented Jul 26, 2022 at 11:38
  • 1
    Thanks so far Cornel, wp menu item add-term main-menu category 1 works now :) Commented Aug 29, 2022 at 10:33


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.