Search.../

queryDraftPosts( )

Retrieves a list of up to 100 draft posts, given the provided paging, filtering, and sorting.

Description

Query Draft Posts runs with these defaults, which you can override:

  • editedDate is sorted in DESC order.
  • paging.limit is 50.
  • paging.offset is 0.
PROPERTYSUPPORTED FILTERS & SORTING
_ideq(),ne(),hasSome(),ascending(),descending()
titleeq(),ne(),startsWith(),hasSome(),exists(),in(),ascending(),descending()
excerpteq(),ne(),startsWith(),hasSome(),exists(),in(),ascending(),descending()
featuredeq(),ne(),ascending(),descending()
categoryIdshasSome(),hasAll()
memberIdeq(),ne(),hasSome()
hashtagshasSome(),hasAll()
commentingEnabledeq(),ne(),ascending(),descending()
minutesToReadeq(),ne(),lt(),le(),gt(),ge(),in()
tagIdshasSome(),hasAll()
pricingPlanIdshasSome(),hasAll()
translationIdeq(),ne(),exists(),in()
languageeq(),ne(),hasSome(),exists(),in()
statuseq(),ne(),hasSome(),exists(),in(),ascending(),descending()
hasUnpublishedChangeseq(),ne(),ascending(),descending()
editedDateeq(),ne(),lt(),le(),gt(),ge(),in(),ascending(),descending()
scheduledPublishDateeq(),ne(),lt(),le(),gt(),ge(),in(),ascending(),descending()
Admin Method

This function requires elevated permissions to run. This function is not universal and runs only on the backend.

Syntax

function queryDraftPosts(options: QueryDraftPostsOptions): DraftPostsQueryBuilder

queryDraftPosts Parameters

NAME
TYPE
DESCRIPTION
options
Optional
QueryDraftPostsOptions

Options for querying draft posts.

Returns

Was this helpful?

Query draft posts using options (export from backend code)

Copy Code
1import { draftPosts } from 'wix-blog-backend';
2import { webMethod, Permissions } from 'wix-web-module';
3
4/* Sample options value:
5 * {
6 * "fieldsets": ["GENERATED_EXCERPT"]
7 * }
8 */
9
10export const myQueryDraftPostsFunction = webMethod(
11 Permissions.Admin,
12 async (options) => {
13 try {
14 const queriedDraftPosts = await draftPosts.queryDraftPosts(options);
15 console.log('Successfully queried draft posts:', queriedDraftPosts);
16 return queriedDraftPosts;
17 } catch (error) {
18 console.error(error);
19 // Handle the error
20 }
21 }
22);
23
24
25/* Promise resolves to:
26 * _items: [
27 * {
28 * _id: "d12f2ef2-c0f6-4913-b04f-aeeba2165b93",
29 * _createdDate: "2024-01-09T11:46:42.933Z",
30 * categoryIds: [
31 * "c8780752-f517-4cf9-9c18-0f9a22d00926",
32 * "590635d7-cc7c-48cb-970c-f8339daa1cfe",
33 * "2b2ccb5a-e709-45a1-8353-bb3332b91297"
34 * ],
35 * changeOrigin: "PRICING_PLANS_CHANGE",
36 * commentingEnabled: true,
37 * contentId: "65afbb218a16969308f29037",
38 * editedDate: "2024-01-16T10:50:33.495Z",
39 * editingSessionId: "4e14aa41-ad7f-4e25-b4c4-df7144002aaf",
40 * excerpt: "This is a excerpt about adding a widget to blog post rich content",
41 * featured: true,
42 * firstPublishedDate: "2024-01-09T11:46:43.034Z",
43 * hashtags: [],
44 * hasUnpublishedChanges: false,
45 * language: "en",
46 * media: {
47 * custom: false,
48 * displayed: true
49 * },
50 * memberId: "c00e8a5c-322b-4e77-8813-002e3ea7e811",
51 * minutesToRead: 15,
52 * mostRecentContributorId: "c00e8a5c-322b-4e77-8813-002e3ea7e811",
53 * paidContentParagraph: 1,
54 * pricingPlanIds: [
55 * "4b265594-133c-4cb0-a3af-b31852cad5e7",
56 * "0a6230d1-fe66-4367-9cce-7d7b17ede8cc",
57 * "4c9646d6-e1fb-4559-9267-1620015082aa"
58 * ],
59 * previewTextParagraph: 1,
60 * relatedPostIds: [
61 * "d655251a-74eb-467d-9beb-1962984b8d94",
62 * "6f4d3a1e-dec6-4818-b8b0-9fb62862aa5b",
63 * "66935097-31c5-4fab-9693-aa1b53aeea77"
64 * ],
65 * seoData: {
66 * settings: {
67 * preventAutoRedirect: false,
68 * keywords: []
69 * },
70 * tags: []
71 * },
72 * seoSlug: "rocket-man",
73 * slugs: [
74 * "rocket-man"
75 * ],
76 * status: "PUBLISHED",
77 * tagIds: [
78 * "a55b2c06-cbec-4d01-a8bb-cd7029056c75",
79 * "6d2e0a31-0f5e-4de8-8fd7-e45352bdfa67",
80 * "d2b0c02b-72c1-45af-ba58-3520cec9abe3"
81 * ],
82 * title: "Arise!",
83 * translations: []
84 * },
85 * {
86 * _id: "c8d50953-b31c-435f-82ec-a53d8bff87b4",
87 * _createdDate: "2023-08-13T13:51:23.823Z",
88 * categoryIds: [],
89 * changeOrigin: "PUBLISH",
90 * commentingEnabled: true,
91 * contentId: "65b0c1aa915ccdb13907fe1f",
92 * coverMedia: {
93 * custom: false,
94 * displayed: true,
95 * enabled: true,
96 * image: "wix:image://v1/75059a_3a3953ba8daa4a419562db4e61c7bee7~mv2.jpg#originWidth=2000&originHeight=3000"
97 * },
98 * editedDate: "2024-01-24T07:52:10.511Z",
99 * editingSessionId: "65b0c1aa915ccdb13907fe1f",
100 * excerpt: "If it wasn't for grit, we wouldn't succeed.",
101 * featured: false,
102 * firstPublishedDate: "2023-03-22T14:16:01.201Z",
103 * hashtags: [
104 * "vacation",
105 * "dream",
106 * "summer",
107 * "hashtag"
108 * ],
109 * hasUnpublishedChanges: false,
110 * language: "en",
111 * media: {
112 * custom: false,
113 * displayed: true,
114 * wixMedia: {
115 * image: "wix:image://v1/75059a_3a3953ba8daa4a419562db4e61c7bee7~mv2.jpg#originWidth=2000&originHeight=3000"
116 * }
117 * },
118 * memberId: "c00e8a5c-322b-4e77-8813-002e3ea7e811",
119 * minutesToRead: 12,
120 * mostRecentContributorId: "c00e8a5c-322b-4e77-8813-002e3ea7e811",
121 * paidContentParagraph: 4,
122 * pricingPlanIds: [],
123 * previewTextParagraph: 4,
124 * relatedPostIds: [],
125 * seoData: {
126 * settings: {
127 * preventAutoRedirect: false,
128 * keywords: []
129 * },
130 * tags: []
131 * },
132 * seoSlug: "the-things-we-carry-and-what-we-can-let-go-of",
133 * slugs: [
134 * "the-things-we-carry-and-what-we-can-let-go-of"
135 * ],
136 * status: "PUBLISHED",
137 * tagIds: [],
138 * title: "Grit is the special sauce.",
139 * translations: []
140 * }
141 * ],
142 * _limit: 50,
143 * _nextCursor: "",
144 * _originQuery: {
145 * filterTree: {
146 * $and: []
147 * },
148 * invalidArguments: [],
149 * encoder: {},
150 * transformationPaths: {},
151 * sort: [
152 * {
153 * fieldName: "title",
154 * order: "ASC"
155 * }
156 * ],
157 * paging: {},
158 * pagingMethod: "CURSOR",
159 * builderOptions: {
160 * cursorWithEmptyFilterAndSort: true
161 * }
162 * },
163 * _prevCursor: "",
164 * cursors: {
165 * next: "",
166 * prev: ""
167 * }
168 * };
169 */
Query draft posts (export from backend code)

Copy Code
1import { draftPosts } from 'wix-blog-backend';
2import { webMethod, Permissions } from 'wix-web-module';
3
4export const myQueryDraftPostsFunction = webMethod(
5 Permissions.Admin,
6 async () => {
7 try {
8 const queriedDraftPosts = await draftPosts.queryDraftPosts();
9 console.log('Successfully queried draft posts:', queriedDraftPosts);
10 return queriedDraftPosts;
11 } catch (error) {
12 console.error(error);
13 // Handle the error
14 }
15 }
16);
17
18/* Promise resolves to:
19 * {
20 * "filterTree": {
21 * "$and": []
22 * },
23 * "invalidArguments": [],
24 * "encoder": {},
25 * "transformationPaths": {},
26 * "sort": [],
27 * "paging": {},
28 * "pagingMethod": "CURSOR",
29 * "builderOptions": {
30 * "cursorWithEmptyFilterAndSort": true
31 * }
32 * }
33 */
Query draft posts (dashboard page code)

Copy Code
1import { draftPosts } from 'wix-blog-backend';
2
3export async function myQueryDraftPostsFunction() {
4 try {
5 const queriedDraftPosts = await draftPosts.queryDraftPosts();
6 console.log('Successfully queried draft posts:', queriedDraftPosts);
7 return queriedDraftPosts;
8 } catch (error) {
9 console.error(error);
10 // Handle the error
11 }
12 }
13
14/* Promise resolves to:
15 * {
16 * "filterTree": {
17 * "$and": []
18 * },
19 * "invalidArguments": [],
20 * "encoder": {},
21 * "transformationPaths": {},
22 * "sort": [],
23 * "paging": {},
24 * "pagingMethod": "CURSOR",
25 * "builderOptions": {
26 * "cursorWithEmptyFilterAndSort": true
27 * }
28 * }
29 */