entity-command icon indicating copy to clipboard operation
entity-command copied to clipboard

Allow wp menu item command to add items of type post_type_archive

Open edwardcasbon opened this issue 7 years ago • 3 comments

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.

edwardcasbon avatar Oct 12 '18 10:10 edwardcasbon

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.

schlessera avatar Oct 23 '18 15:10 schlessera

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).

swissspidy avatar Mar 25 '19 09:03 swissspidy

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

alpipego avatar May 08 '19 11:05 alpipego