The address of the WordPress site.
The headers to be used for the requests.
const wpa = new WPApiHandler(
'https://example.com',
{
"Content-Type": "application/json",
"Authorization": "Basic YOURACCESSTOKEN"
}
);
Private
headersPrivate
server_Asynchronously posts a post to the WordPress site.
Optional
new_post: PostThe post to be posted to the WordPress site.
A promise that resolves to the post that was posted.
const wpa = new WPApiHandler(
'https://example.com',
{
"Content-Type": "application/json",
"Authorization": "Basic YOURACCESSTOKEN"
}
);
const new_post = {
id: 1910,
title: 'New Post',
content: 'This is a new post.',
status: 'publish',
tags: ['test'],
};
const result = await wpa.add_post(new_post);
console.log(result);
Private
add_Asynchronously updates a post on the WordPress site.
A promise that resolves to the post that was updated.
AuthenticationError If the authentication failed.
const wpa = new WPApiHandler(
'https://example.com',
{
"Content-Type": "application/json",
"Authorization": "Basic YOURACCESSTOKEN"
}
);
const updated_post = {
id: 1910,
title: 'Updated Post',
content: 'This is an updated post.',
status: 'publish',
tags: [1, 2, 3],
};
const result = await wpa.update_post(updated_post);
console.log(result);
Private
get_Asynchronously retrieves the events from the WordPress site.
Optional
event_id: numberThe ID of a specific event to be retrieved.
A promise that resolves to an array of events.
const wpa = new WPApiHandler(
'https://example.com',
{
"Content-Type": "application/json",
"Authorization": "Basic YOURACCESSTOKEN"
}
);
const events = await wpa.get_events();
console.log(events);
const events = await wpa.get_events(1);
console.log(events);
Asynchronously retrieves the partners from the WordPress site.
Optional
project: stringThe project of the partners to be retrieved.
A promise that resolves to an array of partners.
const wpa = new WPApiHandler(
'https://example.com',
{
"Content-Type": "application/json",
"Authorization": "Basic YOURACCESSTOKEN"
}
);
const partners = await wpa.get_partners();
console.log(partners);
const partners = await wpa.get_partners('Test');
console.log(partners);
Asynchronously retrieves the personnel from the WordPress site.
Optional
search: stringThe search term to filter the personnel.
A promise that resolves to an array of personnel.
const wpa = new WPApiHandler(
'https://example.com',
{
"Content-Type": "application/json",
"Authorization": "Basic YOURACCESSTOKEN"
}
);
const personnel = await wpa.get_personnel();
console.log(personnel);
const personnel = await wpa.get_personnel('John Doe');
console.log(personnel);
Asynchronously retrieves posts from the WordPress site.
Optional
id: numberThe ID of the post to be retrieved.
Optional
tags: string[]The tags of the posts to be retrieved.
A promise that resolves to an array of posts.
PostNotFoundError If the post does not exist.
const wpa = new WPApiHandler(
'https://example.com',
{
"Content-Type": "application/json",
"Authorization": "Basic YOURACCESSTOKEN"
}
);
const posts = await wpa.get_posts();
console.log(posts);
const post = await wpa.get_posts(1910);
console.log(post);
const posts = await wpa.get_posts(undefined, ['test']);
console.log(posts);
Asynchronously retrieves the tag ID by its slug.
The slug of the tag to be retrieved.
Optional
createIfNotExists: boolean = falseWhether to create the tag if it does not exist.
A promise that resolves to the ID of the tag.
If the tag does not exist and createIfNotExists is false.
const wpa = new WPApiHandler(
'https://example.com',
{
"Content-Type": "application/json",
"Authorization": "Basic YOURACCESSTOKEN"
}
);
const tag_id = await wpa.get_tag_slug('test');
console.log(tag_id);
Asynchronously retrieves the tags by their IDs.
The IDs of the tags to be retrieved.
A promise that resolves to an array of tags.
const wpa = new WPApiHandler(
'https://example.com',
{
"Content-Type": "application/json",
"Authorization": "Basic YOURACCESSTOKEN"
}
);
const tag_ids = [1, 2, 3];
const tags = await wpa.get_tags(tag_ids);
console.log(tags);
Asynchronously retrieves the total number of posts on the WordPress site.
A promise that resolves to the total number of posts.
const wpa = new WPApiHandler(
'https://example.com',
{
"Content-Type": "application/json",
"Authorization": "Basic YOURACCESSTOKEN"
}
);
const total_posts = await wpa.post_len();
console.log(total_posts);
Asynchronously removes a post from the WordPress site.
Optional
id: numberThe ID of the post to be removed from the WordPress site.
A promise that resolves to void.
const wpa = new WPApiHandler(
'https://example.com',
{
"Content-Type": "application/json",
"Authorization": "Basic YOURACCESSTOKEN"
}
);
await wpa.remove_post(1910);
Generated using TypeDoc
Creates a new instance of the WPApiHandler class.