An event that is triggered when a post is created.
The onPostCreated()
event handler runs when a post is created. The PostCreated
object contains information about the post that was created.
Note: Backend events don't work when previewing your site.
function wixBlog_onPostCreated(event: PostCreated): void;
Information about the post that was created.
// Place this code in the events.js file
// of your site's Backend section.
// Add the file if it doesn't exist.
export function wixBlog_onPostCreated(event) {
const postId = event.metadata.entityId;
const memberId = event.entity.memberId;
console.log("Post created", event);
}
/* Full event object:
*
* {
* "metadata":{
* "id":"d1874d29-6525-4e69-8544-e065617d0c42",
* "entityId":"f11052c1-84f1-456e-8583-82173da8509d",
* "eventTime":"2022-06-16T14:42:18.271Z"
* },
* "entity":{
* "_id":"f11052c1-84f1-456e-8583-82173da8509d",
* "categoryIds":[],
* "commentingEnabled":true,
* "contactId":"33d02592-dd28-4eff-9b8e-4c3bb9c737dd",
* "excerpt":"Creating a blog.",
* "featured":false,
* "firstPublishedDate":"2022-06-16T14:42:18.087Z",
* "hashtags":[],
* "language":"en",
* "lastPublishedDate":"2022-06-16T14:42:18.087Z",
* "memberId":"33d02592-dd28-4eff-9b8e-4c3bb9c737dd",
* "minutesToRead":1,
* "pinned": false,
* "preview": false,
* "pricingPlanIds":[],
* "relatedPostIds":[],
* "richContent":{
* "nodes":[
* {
* "type":"PARAGRAPH",
* "_id":"foo",
* "nodes":[
* {
* "type":"TEXT",
* "_id":"",
* "nodes":[],
* "textData":{
* "text":"Creating a blog.",
* "decorations":[]
* }
* }
* ],
* "paragraphData":{
* "textStyle":{
* "textAlignment":"AUTO"
* },
* "indentation":0
* }
* }
* ],
* "metadata":{
* "version":1,
* "createdTimestamp":"2022-06-16T14:42:18.270Z",
* "updatedTimestamp":"2022-06-16T14:42:18.270Z",
* "_id":"253928e4-71bc-41d5-bcb6-35a604ea8229"
* },
* "documentStyle":{}
* },
* "slug":"new-blog-post",
* "tagIds":[],
* "title":"New Blog Post",
* "translationId": "",
* "url":"http://https://tadasz7.wixsite.com/blog-velo-events/post/new-blog-post"
* }
* }
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.