Last active
March 6, 2018 15:17
-
-
Save amielucha/522b9e7a35d7d5f7cc8ba1e402896ea4 to your computer and use it in GitHub Desktop.
WP CLI Recipes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # | |
| # Menus | |
| # | |
| # Note: Add '--porcelain' flag to output the ID of the added item | |
| # Documentation | |
| wp help menu | |
| # List Menu Locations | |
| wp menu location list | |
| # Create a menu | |
| wp menu create "Main Menu" | |
| # Assign it to a location | |
| wp menu location assign main-menu primary | |
| # Add custom menu item | |
| wp menu item add-custom main-menu Amielucha https://amielucha.com | |
| # List all items in 'main-menu' | |
| wp menu item list main-menu | |
| # Update link | |
| wp menu item update 8 --link="#" | |
| # Delete menu items with id 8 and 10 | |
| wp menu item delete 8 10 | |
| # Add multiple pages to the menu (PowerShell) | |
| 5, 4 | foreach { wp menu item add-post main-menu $_ } | |
| # Create a custom link and change its URL | |
| wp menu item add-custom main-menu Example https://amielucha.com --porcelain | foreach { wp menu item update $_ --link="#" } | |
| # | |
| # Pages | |
| # | |
| # List pages | |
| wp post list --post_type=page | |
| # Create a page | |
| wp post create --post_type=page --post_title="Page Title" --post_status=publish | |
| # Create Multiple Pages | |
| 'Page One', 'Page Two' | forEach{ wp post create --post_type=page --post_title=$_ --post_status=publish } | |
| # Create Multiple Pages and add them to the Main Menu ('main-menu') | |
| 'Page One', 'Page Two' | forEach{ wp post create --post_type=page --post_title=$_ --post_status=publish --porcelain | forEach { wp menu item add-post main-menu $_ } } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment