> Portal Navigation: > > - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version. > - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages). > - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`). > - Top-level index of all portals: https://dev.wix.com/docs/llms.txt > - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt # QueryPostCountStats # Package: blog # Namespace: BlogStatsService # Method link: https://dev.wix.com/docs/api-reference/business-solutions/blog/posts-stats/query-post-count.md ## Permission Scopes: Read Blog : SCOPE.DC-BLOG.READ-BLOGS ## Introduction Retrieves the number of published posts per month within a specified time range. The time range is set 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 always ends on the last day of the month. > Note: If there are no published posts in a month within the time range, 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. --- ## REST API ### Schema ``` Method: queryPostCountStats Description: Retrieves the number of published posts per month within a specified time range. The time range is set 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 always ends on the last day of the month. > Note: If there are no published posts in a month within the time range, 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. URL: https://www.wixapis.com/blog/v2/stats/post/count Method: GET Method parameters: query param name: language | type: language | description: Language filter. 2-or-4-letter language code in [IETF BCP 47 language tag](https://en.wikipedia.org/wiki/IETF_language_tag) format. Pass a language to only receive the period post count for that specified language. query param name: months | type: months | description: Number of months to include in response. param name: order | type: Order - enum: UNKNOWN - OLDEST - NEWEST - query param name: rangeStart | type: rangeStart | description: Start of time range to return, in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date and time format. query param name: timeZone | type: timeZone | description: Time zone to use when calculating the start of the month. [UTC timezone offset](https://en.wikipedia.org/wiki/List_of_UTC_offsets) format. For example, New York time zone is `-05`. Return type: QueryPostCountStatsResponse - name: stats | type: array | description: List of published post counts by month. - name: periodStart | type: string | description: Start of time range in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date and time format. - name: postCount | type: integer | description: Number of posts published during this month. ``` ### Examples ### QueryPostCountStats ```curl ~~~cURL curl --request POST 'http://social-blog.wix.com/_api/communities-blog-node-api/v2/stats/posts/count' \ --header 'Authorization: \ --header 'Content-Type: application/json' \ --data-raw '{ "rangeStart": "2018-11-01T00:00:00Z", "order": "OLDEST", "months": 3, "language": "en" }' ~~~ ``` --- ## JavaScript SDK ### Schema ``` Method: wixClientAdmin.blog.BlogStatsService.queryPostCountStats(options) Description: Retrieves the number of published posts per month within a specified time range. The time range is set 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 always ends on the last day of the month. > Note: If there are no published posts in a month within the time range, 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. Method parameters: param name: options | type: QueryPostCountStatsOptions none - name: rangeStart | type: Date | description: Start of time range to return, in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date and time format. - name: order | type: Order | description: Order of returned results. - `OLDEST`: posts by date in ascending order. - `NEWEST`: posts by date in descending order. Default: `OLDEST` - enum: UNKNOWN, OLDEST, NEWEST - name: months | type: integer | description: Number of months to include in response. - name: language | type: string | description: Language filter. 2-or-4-letter language code in [IETF BCP 47 language tag](https://en.wikipedia.org/wiki/IETF_language_tag) format. Pass a language to only receive the period post count for that specified language. - name: timeZone | type: string | description: Time zone to use when calculating the start of the month. [UTC timezone offset](https://en.wikipedia.org/wiki/List_of_UTC_offsets) format. For example, New York time zone is `-05`. Return type: PROMISE - name: stats | type: array | description: List of published post counts by month. - name: periodStart | type: Date | description: Start of time range in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date and time format. - name: postCount | type: integer | description: Number of posts published during this month. ``` ### Examples ### 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. ```javascript import { posts } from '@wix/blog'; /* Sample options value: * { * rangeStart: new Date('2022-03-10'), * months: 4 * } */ export async function queryPostCountStatsFunction(options) { try { const result = await posts.queryPostCountStats(options); const stats = result.stats; const firstMonthPostCount = result.stats[0].postCount; console.log('Retrieved Result:', result); return result; } catch (error) { console.error(error); } } /* Promise resolves to: * { * "stats": [ * { * "periodStart": "2022-03-01T00:00:00.000Z", * "postCount": 9 * }, * { * "periodStart": "2022-04-01T00:00:00.000Z", * "postCount": 6 * }, * { * "periodStart": "2022-05-01T00:00:00.000Z", * "postCount": 1 * }, * { * "periodStart": "2022-06-01T00:00:00.000Z", * "postCount": 2 * } * ] * } */ ``` ### Get post count per month This example uses `queryPostCountStats()` to retrieve the `postCount` of published posts per month. ```javascript import { posts } from '@wix/blog'; export async function queryPostCountStatsFunction() { try { const result = await posts.queryPostCountStats(); const stats = result.stats; const firstMonthPostCount = result.stats[0].postCount; console.log('Retrieved Result:',result); return result; } catch (error) { console.error(error); }; } /* Promise resolves to: * { * "stats": [ * { * "periodStart": "2020-08-01T00:00:00.000Z", * "postCount": 1 * }, * { * "periodStart": "2021-03-01T00:00:00.000Z", * "postCount": 2 * }, * { * "periodStart": "2022-03-01T00:00:00.000Z", * "postCount": 9 * }, * { * "periodStart": "2022-04-01T00:00:00.000Z", * "postCount": 6 * }, * { * "periodStart": "2022-05-01T00:00:00.000Z", * "postCount": 1 * }, * { * "periodStart": "2022-06-01T00:00:00.000Z", * "postCount": 2 * }, * { * "periodStart": "2022-07-01T00:00:00.000Z", * "postCount": 5 * } * ] * } */ ``` ### queryPostCountStats (self-hosted) Self-hosted SDK calls require you to [create a client](https://dev.wix.com/docs/sdk/articles/work-with-the-sdk/about-the-wix-client.md). ```javascript import { createClient } from '@wix/sdk'; import { posts } from '@wix/blog'; // Import the auth strategy for the relevant access type // Import the relevant host module if needed const myWixClient = createClient ({ modules: { posts }, // Include the auth strategy and host as relevant }); async function queryPostCountStats(options) { const response = await myWixClient.posts.queryPostCountStats(options); }; ``` ---