REST API Functions
The REST API functions are a set of functions that can be used to retrieve data from the REST API.
getMenuItems
This function fetches menu items from a WordPress site based on a specified menu slug
. It transforms the flat array of menu items returned by the API into a hierarchical structure.
Required environment variables
- Name
WP_APPLICATION_PASSWORD
- Type
- string
- Description
The application password for the WordPress user.
Required parameters
- Name
slug
- Type
- string
- Description
The slug of the menu.
Returns
- Name
menuItems
- Type
- WpMenuItem
- Description
The menu items of the specified menu.
Request
import { getMenuItems } from '@nextwp/core'
const menuItems = await getMenuItems({ slug: "main-menu" });
Return Type
export interface WpMenuItem {
id?: number;
title?: RenderedObject;
status?: string;
url?: string;
attr_title?: string;
description?: string;
type?: string;
type_label?: string;
object?: string;
object_id?: number;
parent?: number;
menu_order?: number;
target?: string;
classes?: string[];
xfn?: string[];
invalid?: boolean;
meta?: any;
menus?: number;
_links?: WpLink[];
label?: string;
path?: string;
childItems?: WpMenuItem[];
}
getSiteSettings
This function allows you to retrieve your site settings from WordPress.
Required environment variables
- Name
WP_APPLICATION_PASSWORD
- Type
- string
- Description
The application password for the WordPress user.
Returns
- Name
settings
- Type
- WpSettings
- Description
The site settings.
Request
import { getSiteSettings } from '@nextwp/core'
const settings = await getSiteSettings()
Return Type
export interface WpSettings {
title?: string;
description?: string;
url?: string;
posts_per_page?: number;
page_on_front?: number;
page_for_posts?: number;
site_logo?: number;
site_icon?: number;
email?: string;
timezone?: string;
date_format?: string;
time_format?: string;
start_of_week?: number;
language?: string;
use_smilies?: boolean;
default_category?: number;
default_post_format?: string;
show_on_front?: string;
default_ping_status?: string;
default_comment_status?: string;
}
getPageData
This function fetches the data of the page that matches the uri
parameter.
Required environment variables
- Name
WP_APPLICATION_PASSWORD
- Type
- string
- Description
The application password for the WordPress user.
Required parameters
- Name
uri
- Type
- string
- Description
The uri of the page.
Optional parameters
- Name
searchParams
- Type
- string
- Description
The search parameters.
Returns
- Name
data
- Type
- WpPage | ArchivePageData
- Description
The data of the page.
- Name
archive
- Type
- PostType
- Description
The post type archive data if applicable.
- Name
previewData
- Type
- WpPage
- Description
The preview data for the requested page.
Request
import { getPageData } from '@nextwp/core'
const page = await getPageData({ uri: "/", searchParams: "?slug=home"});
Return Type
export interface WpPage {
id: number;
slug?: string;
title?: RenderedObject;
content?: RenderedObject;
excerpt?: RenderedObject;
date?: string;
date_gmt?: string;
modified?: string;
modified_gmt?: string;
guid?: RenderedObject;
link?: string;
status?: "publish" | "future" | "draft" | "pending" | "private";
type?: string;
author?: number;
featured_media?: number;
comment_status?: "open" | "closed";
ping_status?: "open" | "closed";
menu_order?: number;
meta?: any;
template?: string;
yoast_head?: string;
yoast_head_json?: YoastHeadJson;
_links?: EmbeddedLinks;
}
getSingleItem
This function fetches a single item from WordPress based on the id
, uri
, or slug
.
Required environment variables
- Name
WP_APPLICATION_PASSWORD
- Type
- string
- Description
The application password for the WordPress user.
Parameters
- Name
uri
- Type
- string
- Description
The uri of the item.
- Name
id
- Type
- string | integer
- Description
The id of the item.
- Name
slug
- Type
- string
- Description
The slug of the item.
- Name
postTypeRestBase
- Type
- string
- Description
The post type of the item.
Returns
- Name
data
- Type
- WpPage | undefined
- Description
The data of the item.
Request
import { getSingleItem } from '@nextwp/core'
const singleItem = await getSingleItem({ uri: "/", id: "1", slug: "home", postTypeRestBase: "pages"});
Return Type
export interface WpPage {
id: number;
slug?: string;
title?: RenderedObject;
content?: RenderedObject;
excerpt?: RenderedObject;
date?: string;
date_gmt?: string;
modified?: string;
modified_gmt?: string;
guid?: RenderedObject;
link?: string;
status?: "publish" | "future" | "draft" | "pending" | "private";
type?: string;
author?: number;
featured_media?: number;
comment_status?: "open" | "closed";
ping_status?: "open" | "closed";
menu_order?: number;
meta?: any;
template?: string;
yoast_head?: string;
yoast_head_json?: YoastHeadJson;
_links?: EmbeddedLinks;
}
getSiteLogo
This function fetches the site logo from a WordPress site.
Required environment variables
- Name
WP_APPLICATION_PASSWORD
- Type
- string
- Description
The application password for the WordPress user.
Returns
- Name
data
- Type
- WpMediaItem
- Description
The data of the media item.
Request
import { getSiteLogo } from '@nextwp/core'
const siteLogo = await getSiteLogo();
Return Type
export interface WpMediaItem {
id?: number;
date?: string;
date_gmt?: string;
guid?: RenderedObject;
modified?: string;
modified_gmt?: string;
slug?: string;
status?: string;
type?: string;
link?: string;
title?: RenderedObject;
author?: number;
comment_status?: string;
ping_status?: string;
template?: string;
meta?: any[];
acf?: any[];
description?: RenderedObject;
caption?: RenderedObject;
alt_text?: string;
media_type?: string;
mime_type?: string;
media_details?: {
width?: number;
height?: number;
file?: string;
filesize?: number;
sizes?: Record<string, ImageSize>;
image_meta?: ImageMeta;
};
post?: any;
source_url?: string;
_links?: EmbeddedLinks;
}
getSiteIcon
This function fetches the site icon from a WordPress site.
Required environment variables
- Name
WP_APPLICATION_PASSWORD
- Type
- string
- Description
The application password for the WordPress user.
Returns
- Name
data
- Type
- WpMediaItem
- Description
The data of the media item.
Request
import { getSiteIcon } from '@nextwp/core'
const siteIcon = await getSiteIcon();
Return Type
export interface WpMediaItem {
id?: number;
date?: string;
date_gmt?: string;
guid?: RenderedObject;
modified?: string;
modified_gmt?: string;
slug?: string;
status?: string;
type?: string;
link?: string;
title?: RenderedObject;
author?: number;
comment_status?: string;
ping_status?: string;
template?: string;
meta?: any[];
acf?: any[];
description?: RenderedObject;
caption?: RenderedObject;
alt_text?: string;
media_type?: string;
mime_type?: string;
media_details?: {
width?: number;
height?: number;
file?: string;
filesize?: number;
sizes?: Record<string, ImageSize>;
image_meta?: ImageMeta;
};
post?: any;
source_url?: string;
_links?: EmbeddedLinks;
}
getOptionsPage
This function fetches the custom endpoint of the site options page registered by the NextWP Toolkit Plugin
in WordPress.
Environment variables
- Name
WP_APPLICATION_PASSWORD
- Type
- string
- Description
The application password for the WordPress user.
Required parameters
- Name
slug
- Type
- string
- Description
The slug of the options page.
Returns
- Name
data
- Type
- WpMediaItem
- Description
The data of the options page.
Request
import { getOptionsPage } from '@nextwp/core'
const optionsPage = await getOptionsPage({ slug: 'my-options-page' })
Return Type
export interface <object> {
{...options page data}
}