Open
Description
Bug Report
- Yes, I reviewed the contribution guidelines.Yes, more specifically, I reviewed the guidelines on how to write clear bug reports.
Describe the current, buggy behavior
Position is not updated in wp menu item update command.
Describe how other contributors can replicate this bug
wp menu create "Sample Menu"
wp menu item add-custom sample-menu Alpha https://alpha.com
wp menu item add-custom sample-menu Beta https://beta.com
wp menu item list sample-menu --format=csv
db_id,type,title,link,position
1272,custom,Alpha,https://alpha.com,1
1273,custom,Beta,https://beta.com,2
wp menu item update 1273 --link=https://beta.net --position=1
db_id,type,title,link,position
1272,custom,Alpha,https://alpha.com,1
1273,custom,Beta,https://beta.net,2
Describe what you would expect as the correct outcome
Position also should have been updated.
Let us know what environment you are running this on
OS: Darwin 22.6.0 Darwin Kernel Version 22.6.0: Tue Nov 7 21:48:06 PST 2023; root:xnu-8796.141.3.702.9~2/RELEASE_X86_64 x86_64
Shell: /bin/zsh
PHP binary: /usr/local/Cellar/php@8.2/8.2.15/bin/php
PHP version: 8.2.15
php.ini used: /usr/local/etc/php/8.2/php.ini
MySQL binary: /usr/local/bin/mysql
MySQL version: mysql Ver 8.3.0 for macos13.6 on x86_64 (Homebrew)
SQL modes:
WP-CLI root dir: phar://wp-cli.phar/vendor/wp-cli/wp-cli
WP-CLI vendor dir: phar://wp-cli.phar/vendor
WP_CLI phar path: /Users/nilambarsharma/Sites/staging
WP-CLI packages dir: /Users/nilambarsharma/.wp-cli/packages/
WP-CLI cache dir: /Users/nilambarsharma/.wp-cli/cache
WP-CLI global config: /Users/nilambarsharma/.wp-cli/config.yml
WP-CLI project config: /Users/nilambarsharma/Sites/staging/wp-cli.local.yml
WP-CLI version: 2.10.0
Activity
danielbachhuber commentedon Feb 13, 2024
Thanks for the report, @ernilambar !
This definitely seems like a bug. I was able to reproduce with the steps you provided.
With this being said, I'm not sure it ever worked in the first place 🙃
Feel free to submit a pull request, if you'd like. Here is some guidance on our pull request best practices.
ernilambar commentedon Feb 14, 2024
I dug deeper into adding/updating menu item stuffs. Yes, this has not worked till now because when there is new position value,
menu_order
value of all menu items in that menu should shuffled which we have not done.We have done only for
add
:This
reorder_menu_items()
only works for an item and makes sense in adding. We cannot reuse this method. We need to introduce separate method for reshuffling menu order forupdate
.ernilambar commentedon Apr 15, 2024
Related: #493
nateinaction commentedon May 16, 2024
Additional information about this issue.
Slightly simpler reproduction steps
First, I was able to reproduce this issue with a slightly simpler command set by leaving off the
--link
flag during the update call:Create the menu and items:
wp menu create "Sample Menu" wp menu item add-custom sample-menu Alpha https://alpha.com/ wp menu item add-custom sample-menu Beta https://beta.com/
Try to move Beta item to position 1:
Show that Beta did not move:
New behavior discovered by moving first menu element
Oddly enough, even though Beta cannot be moved to position 1, Alpha can be moved to position 2
With Alpha in position 2, both Alpha and Beta can be moved freely:
Move Beta to position 2:
Move Beta back to position 1
However, once Alpha is moved back to position 1 Beta is again prevented from changing position
Move Alpha back to position 1:
Show that Beta did not move:
Edit: I see what's happening. The item update command is always updating the
menu_order
column for the posts in thewp_posts
table. When Alpha and Beta share the same order position, they still display in alphabetical order.petruchek commentedon Sep 11, 2024
@ernilambar, is this still not fixed? I can see that some work was done in #502 but apparently it's not fully working.
ernilambar commentedon Sep 11, 2024
@petruchek Yah, not fixed. That approach did not work without breaking other things. Now in
block
era, this issue does not get enough traction as it is not much used. 😊