Writes each planned topic with AI, saves it to WordPress as a draft, and records the link in your sheet.
Uses
Google Sheets
OpenAIWordPress
Turn a content plan into WordPress drafts
planSpreadsheetUrl to blank.Set planSpreadsheetUrl to blank.planTabName to blank.Set planTabName to blank.audienceAndStyle to blank.Set audienceAndStyle to blank.draftLogTabName to Drafted Posts.Set draftLogTabName to Drafted Posts.maxNewDraftsPerRun to 5.Set maxNewDraftsPerRun to 5.draftLogTabErrorIf a step below fails, save the error as draftLogTabErrorTry
draftLogTabName in planSpreadsheetUrl.Create the tab draftLogTabName in planSpreadsheetUrl.On error
draftLogTabError as text.Show in the output: Did not create the '@draftLogTabName' tab, which is expected once it exists: draftLogTabError as text.planSpreadsheetUrl. Save it as draftLog.Read the rows of planSpreadsheetUrl. Save it as draftLog.draftLog.headers is emptyIf draftLog.headers is emptyYes
draftLogTabName in planSpreadsheetUrl.Add a row to draftLogTabName in planSpreadsheetUrl.No
No steps
alreadyDrafted.Start an empty list and save it as alreadyDrafted.loggedPost in draftLog.rows:For each loggedPost in draftLog.rows:loggedTopicErrorIf a step below fails, save the error as loggedTopicErrorTry
loggedPost.Topic in lowercase to the end of alreadyDrafted and save it as alreadyDrafted.Add loggedPost.Topic in lowercase to the end of alreadyDrafted and save it as alreadyDrafted.On error
planSpreadsheetUrl. Save it as plan.Read the rows of planSpreadsheetUrl. Save it as plan.newDrafts to 0.Set newDrafts to 0.plannedPost in plan.rows:For each plannedPost in plan.rows:newDrafts is greater than or equal to maxNewDraftsPerRunIf newDrafts is greater than or equal to maxNewDraftsPerRunYes
Reached this run's limit of new drafts. The rest of the plan is picked up on the next run..Show in the output: Reached this run's limit of new drafts. The rest of the plan is picked up on the next run..No
No steps
topic to blank.Set topic to blank.topicErrorIf a step below fails, save the error as topicErrorTry
plannedPost.Topic and save it as topic.Trim plannedPost.Topic and save it as topic.On error
topic is emptyIf topic is emptyYes
No
No steps
alreadyDrafted contains topic in lowercaseIf alreadyDrafted contains topic in lowercaseYes
topic.Show in the output: Already drafted, skipping: topic.No
No steps
angle to blank.Set angle to blank.angleErrorIf a step below fails, save the error as angleErrorTry
plannedPost.Angle and save it as angle.Trim plannedPost.Angle and save it as angle.On error
angle to blank.Change angle to blank.brief to Topic: topic.Set brief to Topic: topic.angle isn't emptyIf angle isn't emptyYes
brief to briefChange brief to brief
Angle to take: angle.No
No steps
prompt to You are writing one post for a company blog.Set prompt to You are writing one post for a company blog.
Audience and house style:
audienceAndStyle
brief
Write the finished post body. Return ONLY the body HTML - <h2>, <h3>, <p>, <ul> and <li> tags. Do not include an <h1>, a title line, a code fence, or any commentary before or after the HTML. Aim for 600-900 words, use concrete examples, and do not invent statistics, quotes, customer names, or links.draftHtml to blank.Set draftHtml to blank.writingErrorIf a step below fails, save the error as writingErrorTry
draftHtml.Trim the response text from the OpenAI “Ask OpenAI” step and save it as draftHtml.On error
writingError as text.Show in the output: Could not draft '@topic': writingError as text.draftHtml is emptyIf draftHtml is emptyYes
No
No steps
newPost to nothing.Set newPost to nothing.wordpressErrorIf a step below fails, save the error as wordpressErrorTry
topic. Save it as newPost.Create the post topic. Save it as newPost.draftHtmlOn error
wordpressError as text.Show in the output: Could not create the WordPress draft for '@topic': wordpressError as text.postUrl to blank.Set postUrl to blank.postLinkErrorIf a step below fails, save the error as postLinkErrorTry
newPost.link and save it as postUrl.Trim newPost.link and save it as postUrl.On error
postUrl to blank.Change postUrl to blank.postUrl is emptyIf postUrl is emptyYes
No
No steps
draftLogTabName in planSpreadsheetUrl.Add a row to draftLogTabName in planSpreadsheetUrl.topic in lowercase to the end of alreadyDrafted and save it as alreadyDrafted.Add topic in lowercase to the end of alreadyDrafted and save it as alreadyDrafted.newDrafts.Add 1 to newDrafts.