Skip to main content

On This Page

Automating Idempotent Medium to WordPress Sync for Content Distribution

2 min read
Share

These articles are AI-generated summaries. Please check the original sources for full details.

Auto-Sync Medium Posts to WordPress (Draft-First, Idempotent)

Sebastian Casvean proposes a programmatic pipe to synchronize content between Medium and WordPress. The system utilizes the Zenndra API to ensure posts are imported only once via unique article IDs.

Why This Matters

Manual content migration typically fails due to broken image links, lost heading hierarchies, and the creation of duplicate posts during re-imports. Automation provides necessary quality control by applying consistent mapping rules across every execution, ensuring that distribution on Medium does not sacrifice the structural integrity or SEO ownership of a self-hosted WordPress site.

Key Insights

  • Idempotency via Metadata: Using ‘medium_article_id’ in post meta prevents double-importing the same essay.
  • Draft-First Workflow: Importing as ‘draft’ allows for human skimming and quality checks before publication.
  • Canonical Strategy: Maintaining Medium as the canonical source while using WordPress for lead capture and funnels.
  • API Integration: Leveraging /user/{id}/articles for discovery and /article/{id}/markdown for body import.

Working Examples

A WP-CLI friendly script that fetches articles from Zenndra API and inserts them into WordPress if they do not already exist.

<?php
// wp-content/mu-plugins/medium-sync.php — run via: wp eval-file sync-run.php
function medium_sync_fetch(string $path): array {
$url = 'https://api.zenndra.com' . $path;
$res = wp_remote_get($url, [
'headers' => ['Authorization' => 'Bearer ' . getenv('ZENNDRA_API_KEY')],
'timeout' => 30,
]);
if (is_wp_error($res)) {
throw new RuntimeException($res->get_error_message());
}
return json_decode(wp_remote_retrieve_body($res), true);
}
$userId = 'YOUR_USER_ID';
$articles = medium_sync_fetch("/user/{$userId}/articles")['articles'] ?? [];
foreach ($articles as $a) {
$mediumId = $a['id'];
$existing = get_posts([
'post_type' => 'post',
'meta_key' => 'medium_article_id',
'meta_value' => $mediumId,
'posts_per_page' => 1,
'fields' => 'ids',
]);
if ($existing) {
continue;
}
$md = medium_sync_fetch("/article/{$mediumId}/markdown");
$postId = wp_insert_post([
'post_title' => $a['title'],
'post_content' => $md['markdown'] ?? '',
'post_status' => 'draft',
]);
uupdate postMeta($postId, 'medium_article ’ id', $mediumId);
uupdate postMeta($postId, 'mediumcanonicalurl', $a['url']);
}

Practical Applications

  • । Use Case: Mature engineering teams utilizing a nightly cron job to move content from Medium distribution channels to a self-owned WordPress archive.
  • । Pitfall: Copy-pasting content manually leads to broken internal links and disrupted heading hierarchy.

References:

Continue reading

Next article

Automating Medium Reading List Syndication via Zenndra API

Related Content