queryPostCountStats( )
Retrieves the number of published posts per month within a specified time range.
Description
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. IfrangeStart
is set to'2022-01-01'
andmonths
is set to3
, the response includespostCount
values for January and March, but not February.
Syntax
function queryPostCountStats(options: QueryPostCountStatsOptions): Promise<QueryPostCountStatsResponse>
queryPostCountStats Parameters
NAME
TYPE
DESCRIPTION
Options specifying time frame, sort, and filter.
Returns
Fulfilled - Post count stats.
Return Type:
NAME
TYPE
DESCRIPTION
List of posts in specified order.
Was this helpful?
This example uses queryPostCountStats()
to retrieve the postCount
of published posts per month.
1import { posts } from 'wix-blog-backend';23export async function queryPostCountStatsFunction() {4 try {5 const result = await posts.queryPostCountStats();6 const stats = result.stats;7 const firstMonthPostCount = result.stats[0].postCount;8 console.log('Retrieved Result:',result);9 return result;10 } catch (error) {11 console.error(error);12 };13}1415/* Promise resolves to:16 * {17 * "stats": [18 * {19 * "periodStart": "2020-08-01T00:00:00.000Z",20 * "postCount": 121 * },22 * {23 * "periodStart": "2021-03-01T00:00:00.000Z",24 * "postCount": 225 * },26 * {27 * "periodStart": "2022-03-01T00:00:00.000Z",28 * "postCount": 929 * },30 * {31 * "periodStart": "2022-04-01T00:00:00.000Z",32 * "postCount": 633 * },34 * {35 * "periodStart": "2022-05-01T00:00:00.000Z",36 * "postCount": 137 * },38 * {39 * "periodStart": "2022-06-01T00:00:00.000Z",40 * "postCount": 241 * },42 * {43 * "periodStart": "2022-07-01T00:00:00.000Z",44 * "postCount": 545 * }46 * ]47 * }48 */
This example uses queryPostCountStats()
to retrieve the postCount
of published posts per month.
1import { Permissions, webMethod } from 'wix-web-module';2import { posts } from 'wix-blog-backend';34export const queryPostCountStatsFunction = webMethod(Permissions.Anyone, async () => {5 try {6 const result = await posts.queryPostCountStats();7 const stats = result.stats;8 const firstMonthPostCount = result.stats[0].postCount;9 console.log('Retrieved Result:',result);10 return result;11 } catch (error) {12 console.error(error);13 };14});1516/* Promise resolves to:17 * {18 * "stats": [19 * {20 * "periodStart": "2020-08-01T00:00:00.000Z",21 * "postCount": 122 * },23 * {24 * "periodStart": "2021-03-01T00:00:00.000Z",25 * "postCount": 226 * },27 * {28 * "periodStart": "2022-03-01T00:00:00.000Z",29 * "postCount": 930 * },31 * {32 * "periodStart": "2022-04-01T00:00:00.000Z",33 * "postCount": 634 * },35 * {36 * "periodStart": "2022-05-01T00:00:00.000Z",37 * "postCount": 138 * },39 * {40 * "periodStart": "2022-06-01T00:00:00.000Z",41 * "postCount": 242 * },43 * {44 * "periodStart": "2022-07-01T00:00:00.000Z",45 * "postCount": 546 * }47 * ]48 * }49 */50
This example uses queryPostCountStats()
to retrieve the postCount
of published posts per month within a given time frame.
1import { Permissions, webMethod } from 'wix-web-module';2import { posts } from 'wix-blog-backend';34/* Sample options value:5 * {6 * rangeStart: new Date('2022-03-10'),7 * months: 48 * }9 */1011export const queryPostCountStatsFunction = webMethod(Permissions.Anyone, async (options) => {12 try {13 const result = await posts.queryPostCountStats(options);14 const stats = result.stats;15 const firstMonthPostCount = result.stats[0].postCount;16 console.log('Retrieved Result:',result);17 return result;18 } catch (error) {19 console.error(error);20 };21});222324/* Promise resolves to:25 * {26 * "stats": [27 * {28 * "periodStart": "2022-03-01T00:00:00.000Z",29 * "postCount": 930 * },31 * {32 * "periodStart": "2022-04-01T00:00:00.000Z",33 * "postCount": 634 * },35 * {36 * "periodStart": "2022-05-01T00:00:00.000Z",37 * "postCount": 138 * },39 * {40 * "periodStart": "2022-06-01T00:00:00.000Z",41 * "postCount": 242 * }43 * ]44 * }45 */46