WordPress API SDK

Menus extends AbstractResource
in package

Table of Contents

Properties

$baseUrl  : string
$client  : Client
$endpoint  : string

Methods

__construct()  : mixed
all()  : PaginatedResponse
Fetch all items with optional parameters
buildHierarchy()  : array<int, array<string, mixed>>
Build hierarchical menu structure
get()  : array<string, mixed>
Fetch a single item by ID
getBaseUrl()  : string
Get the base URL
getByLocation()  : array<string, mixed>|null
Get menu by location (e.g., 'primary', 'footer')
getBySlug()  : array<string, mixed>
Get menu by slug
getBySlugWithItems()  : array{menu: array, items: array}
Get menu by slug with its items
getHttpClient()  : Client
Get the HTTP client
getItems()  : array<int, array<string, mixed>>
Get menu items for a specific menu
getWithItems()  : array{menu: array, items: array}
Get menu with its items
language()  : QueryBuilder
Filter by language (WPML support)
orderBy()  : QueryBuilder
Set order by
page()  : QueryBuilder
Set page number
perPage()  : QueryBuilder
Set results per page
query()  : PaginatedResponse
Custom query with parameters
search()  : QueryBuilder
Search within the resource
where()  : QueryBuilder
Start building a query

Properties

Methods

__construct()

public __construct(Client $client, string $baseUrl, string $endpoint) : mixed
Parameters
$client : Client
$baseUrl : string
$endpoint : string

buildHierarchy()

Build hierarchical menu structure

public buildHierarchy(array<int, array<string, mixed>> $items) : array<int, array<string, mixed>>

Organizes flat menu items into a hierarchical tree structure.

Parameters
$items : array<int, array<string, mixed>>

Flat array of menu items

Return values
array<int, array<string, mixed>>

Hierarchical menu structure

getBaseUrl()

Get the base URL

public getBaseUrl() : string
Return values
string

getByLocation()

Get menu by location (e.g., 'primary', 'footer')

public getByLocation(string $location) : array<string, mixed>|null

Note: This requires the menu location to be set in WordPress theme.

Parameters
$location : string

Menu location slug

Tags
throws
WordPressApiException
Return values
array<string, mixed>|null

getBySlug()

Get menu by slug

public getBySlug(string $slug) : array<string, mixed>
Parameters
$slug : string
Tags
throws
NotFoundException
Return values
array<string, mixed>

getBySlugWithItems()

Get menu by slug with its items

public getBySlugWithItems(string $slug) : array{menu: array, items: array}
Parameters
$slug : string

Menu slug

Tags
throws
NotFoundException
WordPressApiException
Return values
array{menu: array, items: array}

getHttpClient()

Get the HTTP client

public getHttpClient() : Client
Return values
Client

getItems()

Get menu items for a specific menu

public getItems(int $menuId) : array<int, array<string, mixed>>
Parameters
$menuId : int

Menu ID or term_id

Tags
throws
WordPressApiException
Return values
array<int, array<string, mixed>>

getWithItems()

Get menu with its items

public getWithItems(int $menuId) : array{menu: array, items: array}

This is a convenience method that fetches both the menu and its items.

Parameters
$menuId : int

Menu ID

Tags
throws
NotFoundException
WordPressApiException
Return values
array{menu: array, items: array}
On this page

Search results