From 970f509ad48aed05ac849350c17286de861b9e3e Mon Sep 17 00:00:00 2001 From: OliverGiertz Date: Sat, 21 Mar 2026 11:15:39 +0000 Subject: [PATCH] feat(wordpress): store suggested publish date directly in WP draft Reserve the publish slot before creating the WP draft so the scheduled_publish_at timestamp is available when building the post payload. WordPress receives the `date` field (e.g. 2026-03-24T09:00:00) which sets the scheduled publish time on the draft. Co-Authored-By: Claude Sonnet 4.6 --- backend/app/pipeline.py | 13 ++++++++----- backend/app/wordpress.py | 3 +++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/backend/app/pipeline.py b/backend/app/pipeline.py index f86ef35..e85f944 100644 --- a/backend/app/pipeline.py +++ b/backend/app/pipeline.py @@ -276,16 +276,16 @@ def _process_article(article: dict[str, Any], stats: PipelineStats, settings: An else: # Auto-process: rewrite + WP draft try: - # Reload article to get updated image_review + # Reserve publish slot FIRST so it's available when WP draft is created + slot = reserve_publish_slot(article_id) + + # Reload article to get updated image_review + scheduled_publish_at fresh = get_article_by_id(article_id) if not fresh: return wp_post_id, wp_post_url = _do_rewrite_and_draft(fresh) stats.drafts_created += 1 - # Reserve publish slot - slot = reserve_publish_slot(article_id) - # Reload for notification final = get_article_by_id(article_id) if final: @@ -357,8 +357,11 @@ def override_rejected_article(article_id: int) -> None: except Exception: score = 0 - wp_post_id, wp_post_url = _do_rewrite_and_draft(fresh) + # Reserve publish slot FIRST so it's in the DB when WP draft is created slot = reserve_publish_slot(article_id) + fresh = get_article_by_id(article_id) + + wp_post_id, wp_post_url = _do_rewrite_and_draft(fresh) final = get_article_by_id(article_id) if final: diff --git a/backend/app/wordpress.py b/backend/app/wordpress.py index 704d428..b031e9d 100644 --- a/backend/app/wordpress.py +++ b/backend/app/wordpress.py @@ -335,6 +335,9 @@ def publish_article_draft(article: dict[str, Any]) -> tuple[int, str | None]: payload["excerpt"] = excerpt if featured_media_id: payload["featured_media"] = featured_media_id + scheduled_at = article.get("scheduled_publish_at") + if scheduled_at: + payload["date"] = scheduled_at # e.g. "2026-03-24T09:00:00" wp_post_id = article.get("wp_post_id") tag_ids = _resolve_wp_tag_ids(