Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wp menu item add-custom|add-post|add-term Doesn't Calculate menu_order #493

Open
daleharrison opened this issue Dec 13, 2018 · 4 comments
Open

Comments

@daleharrison
Copy link

daleharrison commented Dec 13, 2018

$ wp menu item add … takes the --position argument literally and inserts it into the database exactly as specified. This is a problem when you are trying to insert one menu item between two others.

For example, on a site that already has a handful of menu links (one of which is in position 3), let's add an item like so:

$ wp menu item add-post example-menu 123 --position=3

In the wp_posts table, the two menu links will have the same menu_order value. This creates mixed results on the frontend of WordPress.

Now, if I go to the menu manager in WordPress and click Save Menu, WordPress recalculates and updates the duplicate menu_order values.

Can WP-CLI do what WordPress is doing here?

@ddarbyson
Copy link

Yup, I experience this too... After using --position option, my db results also show duplicated menu_order values.

wp_posts table:

menu_order
-----------
1
2
3 <- duplicate
3 <- duplicate
4
5
6


@ddarbyson
Copy link

Here's a screenshot to show wp_posts table when filtering by nav_menu_item

screenshot 2018-12-13 21 27 05

@petruchek
Copy link
Contributor

petruchek commented Nov 5, 2019

Hi there @schlessera

I'm new to github (and your project). Can I ask you to review this commit: petruchek@0311008

My questions are:

  1. Does this approach look like the proper way to fix this bug?
  2. If yes, what tests do you suggest I add before sending a PR?

N.B. I'm also changing menu orders when delete command is called.

Here's the branch: https://github.com/petruchek/entity-command/tree/wp-cli-issue-5047
since I'm adding to it

@petruchek
Copy link
Contributor

Hi there, please have a look at the following PR:
#275 and let me know what's missing.

@ernilambar ernilambar transferred this issue from wp-cli/wp-cli Apr 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants