queryDraftPosts( )


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

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()
Authentication

This function requires elevated permissions and runs only on the backend and on dashboard pages.

Permissions
Manage Blog
Learn more about app permissions.
Method Declaration
Copy
function queryDraftPosts(
  options: QueryDraftPostsOptions,
): DraftPostsQueryBuilder;
Method Parameters
optionsQueryDraftPostsOptions

Options for querying draft posts.

Returns
JavaScript
import { draftPosts } from "wix-blog-backend"; import { webMethod, Permissions } from "wix-web-module"; /* Sample options value: * { * "fieldsets": ["GENERATED_EXCERPT"] * } */ export const myQueryDraftPostsFunction = webMethod( Permissions.Admin, async (options) => { try { const queriedDraftPosts = await draftPosts.queryDraftPosts(options); console.log("Successfully queried draft posts:", queriedDraftPosts); return queriedDraftPosts; } catch (error) { console.error(error); // Handle the error } }, ); /* Promise resolves to: * _items: [ * { * _id: "d12f2ef2-c0f6-4913-b04f-aeeba2165b93", * _createdDate: "2024-01-09T11:46:42.933Z", * categoryIds: [ * "c8780752-f517-4cf9-9c18-0f9a22d00926", * "590635d7-cc7c-48cb-970c-f8339daa1cfe", * "2b2ccb5a-e709-45a1-8353-bb3332b91297" * ], * changeOrigin: "PRICING_PLANS_CHANGE", * commentingEnabled: true, * contentId: "65afbb218a16969308f29037", * editedDate: "2024-01-16T10:50:33.495Z", * editingSessionId: "4e14aa41-ad7f-4e25-b4c4-df7144002aaf", * excerpt: "This is a excerpt about adding a widget to blog post rich content", * featured: true, * firstPublishedDate: "2024-01-09T11:46:43.034Z", * hashtags: [], * hasUnpublishedChanges: false, * language: "en", * media: { * custom: false, * displayed: true * }, * memberId: "c00e8a5c-322b-4e77-8813-002e3ea7e811", * minutesToRead: 15, * mostRecentContributorId: "c00e8a5c-322b-4e77-8813-002e3ea7e811", * paidContentParagraph: 1, * pricingPlanIds: [ * "4b265594-133c-4cb0-a3af-b31852cad5e7", * "0a6230d1-fe66-4367-9cce-7d7b17ede8cc", * "4c9646d6-e1fb-4559-9267-1620015082aa" * ], * previewTextParagraph: 1, * relatedPostIds: [ * "d655251a-74eb-467d-9beb-1962984b8d94", * "6f4d3a1e-dec6-4818-b8b0-9fb62862aa5b", * "66935097-31c5-4fab-9693-aa1b53aeea77" * ], * seoData: { * settings: { * preventAutoRedirect: false, * keywords: [] * }, * tags: [] * }, * seoSlug: "rocket-man", * slugs: [ * "rocket-man" * ], * status: "PUBLISHED", * tagIds: [ * "a55b2c06-cbec-4d01-a8bb-cd7029056c75", * "6d2e0a31-0f5e-4de8-8fd7-e45352bdfa67", * "d2b0c02b-72c1-45af-ba58-3520cec9abe3" * ], * title: "Arise!", * translations: [] * }, * { * _id: "c8d50953-b31c-435f-82ec-a53d8bff87b4", * _createdDate: "2023-08-13T13:51:23.823Z", * categoryIds: [], * changeOrigin: "PUBLISH", * commentingEnabled: true, * contentId: "65b0c1aa915ccdb13907fe1f", * coverMedia: { * custom: false, * displayed: true, * enabled: true, * image: "wix:image://v1/75059a_3a3953ba8daa4a419562db4e61c7bee7~mv2.jpg#originWidth=2000&originHeight=3000" * }, * editedDate: "2024-01-24T07:52:10.511Z", * editingSessionId: "65b0c1aa915ccdb13907fe1f", * excerpt: "If it wasn't for grit, we wouldn't succeed.", * featured: false, * firstPublishedDate: "2023-03-22T14:16:01.201Z", * hashtags: [ * "vacation", * "dream", * "summer", * "hashtag" * ], * hasUnpublishedChanges: false, * language: "en", * media: { * custom: false, * displayed: true, * wixMedia: { * image: "wix:image://v1/75059a_3a3953ba8daa4a419562db4e61c7bee7~mv2.jpg#originWidth=2000&originHeight=3000" * } * }, * memberId: "c00e8a5c-322b-4e77-8813-002e3ea7e811", * minutesToRead: 12, * mostRecentContributorId: "c00e8a5c-322b-4e77-8813-002e3ea7e811", * paidContentParagraph: 4, * pricingPlanIds: [], * previewTextParagraph: 4, * relatedPostIds: [], * seoData: { * settings: { * preventAutoRedirect: false, * keywords: [] * }, * tags: [] * }, * seoSlug: "the-things-we-carry-and-what-we-can-let-go-of", * slugs: [ * "the-things-we-carry-and-what-we-can-let-go-of" * ], * status: "PUBLISHED", * tagIds: [], * title: "Grit is the special sauce.", * translations: [] * } * ], * _limit: 50, * _nextCursor: "", * _originQuery: { * filterTree: { * $and: [] * }, * invalidArguments: [], * encoder: {}, * transformationPaths: {}, * sort: [ * { * fieldName: "title", * order: "ASC" * } * ], * paging: {}, * pagingMethod: "CURSOR", * builderOptions: { * cursorWithEmptyFilterAndSort: true * } * }, * _prevCursor: "", * cursors: { * next: "", * prev: "" * } * }; */
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?