Wp menu item list (WP-CLI)

Uit De Vliegende Brigade
Naar navigatie springen Naar zoeken springen

Verkrijg een lijst van menu's in het actieve thema. Die lijst heb je nodig als je menu-items wilt bewerken, omdat je dan de slug, naam of ID van het bijbehorende menu moet geven. De lijst van menu's is doorgaans nogal statisch en voorspelbaar - Zie het voorbeeld onderaan dit hoofdstuk:

$ wp help menu item list

NAME

  wp menu item list

DESCRIPTION

  Gets a list of items associated with a menu.

SYNOPSIS

  wp menu item list <menu> [--fields=<fields>] [--format=<format>]

OPTIONS

  <menu>
    The name, slug, or term ID for the menu.

  [--fields=<fields>]
    Limit the output to specific object fields.

  [--format=<format>]
    Render output in a particular format.
    ---
    default: table
    options:
      - table
      - csv
      - json
      - count
      - ids
      - yaml
    ---

AVAILABLE FIELDS

  These fields will be displayed by default for each menu item:

  * db_id
  * type
  * title
  * link
  * position

  These fields are optionally available:

  * menu_item_parent
  * object_id
  * object
  * type
  * type_label
  * target
  * attr_title
  * description
  * classes
  * xfn

EXAMPLES

    $ wp menu item list main-menu
    +-------+-----------+-------------+---------------------------------+----------+
    | db_id | type      | title       | link                            | position |
    +-------+-----------+-------------+---------------------------------+----------+
    | 5     | custom    | Home        | http://example.com              | 1        |
    | 6     | post_type | Sample Page | http://example.com/sample-page/ | 2        |
    +-------+-----------+-------------+---------------------------------+----------+

Voorbeeld

$ wp menu list

+---------+-------------------------+-------------------------+----------------------+-------+
| term_id | name                    | slug                    | locations            | count |
+---------+-------------------------+-------------------------+----------------------+-------+
| 17      | Main menu               | main-menu               | primary              | 56    |
| 1646    | Mobile Bottom Menu      | mobile-bottom-menu      | mobile-bottom,footer | 7     |
| 1645    | Mobile Top Menu         | mobile-top-menu         | mobile-top           | 12    |
| 22      | Product categories menu | product-categories-menu | product_categories   | 1     |
| 44753   | Utility menu            | utility-menu            | utility              | 1     |
+---------+-------------------------+-------------------------+----------------------+-------+


$ wp menu item list main-menu

+-------+-----------+-----------------------------------------+-------------------------------------------+----------+
| db_id | type      | title                                   | link                                      | position |
+-------+-----------+-----------------------------------------+-------------------------------------------+----------+
| 60057 | post_type | Widgets op Merk                         | http://en.s1/alle-merken/                 | 1        |
| 52263 | post_type | ABL                                     | http://en.s1/widgets12345-voor-aeg-kies-j | 2        |
|       |           |                                         | e-apparaat/                               |          |
| 52264 | post_type | Black & Blacker                         | http://en.s1/widgets12345-voor-black-deck | 3        |
|       |           |                                         | er-kies-je-apparaat/                      |          |
| 61499 | custom    | Bros                                    | http://en.s1/widgets12345-voor-bosch-kies | 4        |
|       |           |                                         | -je-apparaat/                             |          |
| 52266 | post_type | DeWil                                   | http://en.s1/widgets12345-voor-de-walt-ki | 5        |
|       |           |                                         | es-je-apparaat/                           |          |
| 52267 | post_type | Fenn                                    | http://en.s1/widgets12345-voor-fein-kies- | 6        |
+-------+-----------+-----------------------------------------+-------------------------------------------+----------+