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';23export 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}1213/* Promise resolves to:14 * {15 * "total": 1916 * }17 */18
Get the total amount of posts in the blog (export from backend code)
Copy Code
1import { Permissions, webMethod } from 'wix-web-module';2import { posts } from 'wix-blog-backend';34export const getTotalPostsFunction = webMethod(Permissions.Anyone, async () => {5 try {6 const result = await posts.getTotalPosts();7 console.log('Retrieved Result:', result);8 return result;9 } catch (error) {10 console.log(error);11 }12});131415/* Promise resolves to:16 * {17 * "total": 1918 * }19 */20
Get total number of posts in a specified language
Copy Code
1import { Permissions, webMethod } from 'wix-web-module';2import { posts } from 'wix-blog-backend';34/* Sample options value:5 * {6 * language: 'en'7 * }8 */910export const getTotalPostsFunction = webMethod(Permissions.Anyone, async (options) => {11 try {12 const getTotalPostsResult = await posts.getTotalPosts(options);13 console.log('Success! Retrieved getTotalPostsResult:', getTotalPostsResult);14 return getTotalPostsResult;15 } catch (error) {16 console.log(error);17 }18});192021/* Promise resolves to:22 * {23 * "total": 1724 * }25 */26