Search.../

getTotalPosts( )

Gets the total amount of published posts on the blog.

Description

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.

Syntax

function getTotalPosts(options: GetTotalPostsOptions): Promise<GetTotalPostsResponse>

getTotalPosts Parameters

NAME
TYPE
DESCRIPTION
options
Optional
GetTotalPostsOptions

Language Options.

Returns

Fulfilled - Total number of posts.

Return Type:

Promise<
GetTotalPostsResponse
>
NAME
TYPE
DESCRIPTION
total
number

Total amount of published posts.

Was this helpful?

Get the total amount of posts in the blog

Copy Code
1import { posts } from wix-blog-backend;
2
3export async function getTotalPostsFunction() {
4 try {
5 const result = await posts.getTotalPosts();
6 console.log('Retrieved Result:', result);
7 return result;
8 } catch (error) {
9 console.log(error);
10 }
11}
12
13
14/* Promise resolves to:
15 * {
16 * "total": 19
17 * }
18 */
Get total number of posts in a specified language

Copy Code
1import { posts } from wix-blog-backend;
2
3/* Sample options value:
4 * {
5 * language: 'en'
6 * }
7 */
8
9export async function getTotalPostsFunction(options) {
10 try {
11 const getTotalPostsResult = await posts.getTotalPosts(options);
12 console.log('Success! Retrieved getTotalPostsResult:', getTotalPostsResult);
13 return getTotalPostsResult;
14 } catch (error) => {
15 console.log(error);
16 }
17}
18
19
20/* Promise resolves to:
21 * {
22 * "total": 17
23 * }
24 */