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

Allow wp menu item command to add items of type post_type_archive #214

Open
edwardcasbon opened this issue Oct 12, 2018 · 3 comments
Open

Comments

@edwardcasbon
Copy link

The wp menu item command allows for adding links to pages, links to posts and custom links, but doesn't allow for adding links to post type archive pages.

Please could this be added?

E.g. wp menu item add-archive

Thanks.

@schlessera
Copy link
Member

The current items match what the default admin backend provides:

image 2018-10-23 at 5 27 51 pm

I don't think we need to limit ourselves to that, but if we go beyond "out-of-the-box" functionality, we should discuss what the scope we want to support should be. Just adding one random extension seems to arbitrary to my taste.

For now, I wonder whether we should just add a --relative flag to the menu item add-custom variant. This would allow for easy adding of the above archive pages, as well as many other types of links.

As an example, to add the CPT archive of a post that has a slug of books, we could use the following syntax:

wp menu item add-custom --relative my-menu "My Books" books

The --relative flag would let WP-CLI turn books into https://my-domain.com/books.

@swissspidy
Copy link
Member

I don't think we need to limit ourselves to that, but if we go beyond "out-of-the-box" functionality, we should discuss what the scope we want to support should be. Just adding one random extension seems to arbitrary to my taste.

FWIW Post type archive menu links are natively supported in WordPress (show_in_nav_menus option when registering a post type).

@alpipego
Copy link

alpipego commented May 8, 2019

FWIW Post type archive menu links are natively supported in WordPress (show_in_nav_menus option when registering a post type).

Moreover they are supported by the wp_update_nav_menu_item function. You can set the menu-item-type to post_type_archive and the menu-item-object to the post_type (e.g. post).

https://github.com/WordPress/WordPress/blob/bfcd57d327a0654777c3a42c39de313fcae55795/wp-includes/nav-menu.php#L476-L481

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