Search.../

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. 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.

Syntax

function queryPostCountStats(options: QueryPostCountStatsOptions): Promise<QueryPostCountStatsResponse>

queryPostCountStats Parameters

NAME
TYPE
DESCRIPTION
options
Optional
QueryPostCountStatsOptions

Options specifying time frame, sort, and filter.

Returns

Fulfilled - Post count stats.

Return Type:

Promise<
QueryPostCountStatsResponse
>
NAME
TYPE
DESCRIPTION
stats
Array<
PeriodPostCount
>

List of posts in specified order.

Was this helpful?

Get post count per month

This example uses queryPostCountStats() to retrieve the postCount of published posts per month.

Copy Code
1import { posts } from 'wix-blog-backend';
2
3export 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}
14
15/* Promise resolves to:
16 * {
17 * "stats": [
18 * {
19 * "periodStart": "2020-08-01T00:00:00.000Z",
20 * "postCount": 1
21 * },
22 * {
23 * "periodStart": "2021-03-01T00:00:00.000Z",
24 * "postCount": 2
25 * },
26 * {
27 * "periodStart": "2022-03-01T00:00:00.000Z",
28 * "postCount": 9
29 * },
30 * {
31 * "periodStart": "2022-04-01T00:00:00.000Z",
32 * "postCount": 6
33 * },
34 * {
35 * "periodStart": "2022-05-01T00:00:00.000Z",
36 * "postCount": 1
37 * },
38 * {
39 * "periodStart": "2022-06-01T00:00:00.000Z",
40 * "postCount": 2
41 * },
42 * {
43 * "periodStart": "2022-07-01T00:00:00.000Z",
44 * "postCount": 5
45 * }
46 * ]
47 * }
48 */
Get post count per month within a given time period

This example uses queryPostCountStats() to retrieve the postCount of published posts per month within a given time frame.

Copy Code
1import { posts } from 'wix-blog-backend';
2
3/* Sample options value:
4 * {
5 * rangeStart: new Date('2022-03-10'),
6 * months: 4
7 * }
8 */
9
10export async function queryPostCountStatsFunction(options) {
11 try {
12 const result = await posts.queryPostCountStats(options);
13 const stats = result.stats;
14 const firstMonthPostCount = result.stats[0].postCount;
15 console.log('Retrieved Result:',result);
16 return result;
17 } catch (error) {
18 console.error(error);
19 };
20}
21
22
23/* Promise resolves to:
24 * {
25 * "stats": [
26 * {
27 * "periodStart": "2022-03-01T00:00:00.000Z",
28 * "postCount": 9
29 * },
30 * {
31 * "periodStart": "2022-04-01T00:00:00.000Z",
32 * "postCount": 6
33 * },
34 * {
35 * "periodStart": "2022-05-01T00:00:00.000Z",
36 * "postCount": 1
37 * },
38 * {
39 * "periodStart": "2022-06-01T00:00:00.000Z",
40 * "postCount": 2
41 * }
42 * ]
43 * }
44 */