Setup
To use the Posts API, install the @wix/blog
package using npm or Yarn:
1npm install @wix/blog
or
1yarn add @wix/blog
Then import { posts }
from @wix/blog
:
1import { posts } from '@wix/blog'
Gets a post by the specified ID.
The getPost()
function returns a Promise that resolves to a post whose ID matches the given ID.
Permission Scopes
For app development, you must have one of the following permission scopes:function getPost(postId: string, options: GetPostOptions): Promise<GetPostResponse>
Post ID.
Options specifying which fields to return.
Gets a post by the provided slug.
The getPostBySlug()
function returns a Promise that resolves to a post whose slug matches the given slug.
The slug
is the end of a post's URL that refers to a specific post. For example, if a post's URL is https:/example.com/blog/post/my-post-slug
, the slug is my-post-slug
. The slug is case-sensitive, and is generally derived from the post title, unless specified otherwise.
Permission Scopes
For app development, you must have one of the following permission scopes:function getPostBySlug(slug: string, options: GetPostBySlugOptions): Promise<GetPostBySlugResponse>
Slug of the post to retrieve.
The end of a post's URL, for example, https:/example.com/blog/post/my-post-slug. Case sensitive and generally based on the post title if not specified.
Options specifying which fields to return.
Gets a specified post's metrics.
The getPostMetrics()
function returns a Promise that resolves to the specified post's metrics.
A post's metrics include the comments, likes, and views the post receives.
Permission Scopes
For app development, you must have one of the following permission scopes:function getPostMetrics(postId: string): Promise<GetPostMetricsResponse>
Post ID.
Gets the total amount of published posts on the blog.
The getTotalPosts()
function returns a Promise that resolves to the total amount of published posts on your blog's site.
You can use the language
option to filter posts for a specified language.
Permission Scopes
For app development, you must have one of the following permission scopes:function getTotalPosts(options: GetTotalPostsOptions): Promise<GetTotalPostsResponse>
Language Options.
Retrieves a list of published posts.
The listPosts()
function returns a Promise that resolves to a list of up to 100 published posts.
Using the options
parameter, you can filter your list of posts, set the amount of posts to be returned, and sort your list in a specified order.
By default, the list is sorted by firstPublishedDate
in descending order, and the amount of posts returned is 50.
Permission Scopes
For app development, you must have one of the following permission scopes:function listPosts(options: ListPostsOptions): Promise<ListPostsResponse>
Sort, filter, and paging options.
Retrieves the number of published posts per month within a specified time range.
The queryPostCountStats()
function returns a Promise that resolves to the number of posts per month within the specified time range.
You can set the time range using the rangeStart
and months
properties. The time range always starts on the 1st day of the month set in rangeStart
and includes the number of months
following rangeStart
. For example, if rangeStart
is set to '2022-03-13'
and months
is set to 4
, the time range will be from '2022-03-01'
until '2022-06-30'
. The time range ends on the last day of the month.
Note: If there are no published posts in a specific month, that month is not included in the response. For example, let's say a blog has 0
posts dated in February 2022. If rangeStart
is set to '2022-01-01'
and months
is set to 3
, the response includes postCount
values for January and March, but not February.
Permission Scopes
For app development, you must have one of the following permission scopes:function queryPostCountStats(options: QueryPostCountStatsOptions): Promise<QueryPostCountStatsResponse>
Options specifying time frame, sort, and filter.
Creates a query to retrieve a list of posts.
The queryPosts()
function builds a query to retrieve a list of up to 100 posts, and returns a PostsQueryBuilder
object.
The returned object contains the query definition which is typically used to run the query using the find()
function.
You can refine the query by chaining PostsQueryBuilder
functions onto the query. PostsQueryBuilder
functions enable you to sort, filter, and control the results that queryPosts()
returns.
queryPosts()
runs with these PostsQueryBuilder
defaults that can be overridden:
Note that the default limit is '50'
, but the max limit is '100'
.
To learn how to query posts, refer to the table below.
The following PostsQueryBuilder
functions are supported for the queryPosts()
function. For a full description of the Posts object, see the object returned for the items
property in PostsQueryResult
.
Permission Scopes
For app development, you must have one of the following permission scopes:function queryPosts(options: QueryPostsOptions): PostsQueryBuilder
Options specifying which fields to return.