<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>API Integration Tutorials Archives - WP-CLI Mastery</title>
	<atom:link href="https://wpclimastery.com/blog/category/api-integration-tutorials/feed/" rel="self" type="application/rss+xml" />
	<link>https://wpclimastery.com/blog/category/api-integration-tutorials/</link>
	<description>Automate WordPress Like a DevOps Pro.</description>
	<lastBuildDate>Mon, 24 Nov 2025 11:16:47 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://wpclimastery.com/wp-content/uploads/2025/11/cropped-favicon-32x32.webp</url>
	<title>API Integration Tutorials Archives - WP-CLI Mastery</title>
	<link>https://wpclimastery.com/blog/category/api-integration-tutorials/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Automate WordPress Content with AI APIs and WP-CLI (Claude, OpenAI)</title>
		<link>https://wpclimastery.com/blog/automate-wordpress-content-with-ai-apis-and-wp-cli-claude-openai/</link>
		
		<dc:creator><![CDATA[Krasen]]></dc:creator>
		<pubDate>Fri, 20 Feb 2026 09:00:00 +0000</pubDate>
				<category><![CDATA[API Integration Tutorials]]></category>
		<category><![CDATA[ai wordpress content]]></category>
		<category><![CDATA[automated content generation]]></category>
		<category><![CDATA[claude api wordpress]]></category>
		<category><![CDATA[openai wordpress]]></category>
		<category><![CDATA[wp-cli ai automation]]></category>
		<guid isPermaLink="false">https://wpclimastery.com/?p=163</guid>

					<description><![CDATA[<p>Creating quality WordPress content at scale is time-consuming—researching topics, writing articles, editing drafts, and formatting posts manually limits how much you can publish. Writers spend hours producing content that AI...</p>
<p>The post <a href="https://wpclimastery.com/blog/automate-wordpress-content-with-ai-apis-and-wp-cli-claude-openai/">Automate WordPress Content with AI APIs and WP-CLI (Claude, OpenAI)</a> appeared first on <a href="https://wpclimastery.com">WP-CLI Mastery</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Creating quality WordPress content at scale is time-consuming—researching topics, writing articles, editing drafts, and formatting posts manually limits how much you can publish. Writers spend hours producing content that AI could generate in minutes.</p>



<p>AI-powered content generation with WP-CLI automates WordPress publishing—generate articles from prompts, create variations, translate content, optimize for SEO, and publish directly to WordPress. Combine Claude API or OpenAI with WP-CLI for scalable content workflows.</p>



<p>In this guide, you’ll learn to build AI content generation systems for WordPress using WP-CLI, with ethical guidelines, API integration patterns, and automation workflows for responsible AI-assisted publishing.</p>



<h3 class="wp-block-heading" id="ethics">AI Content Generation Ethics</h3>



<p>Before building AI content systems, understand ethical implications and responsible use.</p>



<h4 class="wp-block-heading" id="ethical-considerations">Ethical Considerations</h4>



<p><strong>Transparency</strong>: Disclose AI-generated content to readers when appropriate.</p>



<p><strong>Quality control</strong>: Review and edit AI output before publishing.</p>



<p><strong>Originality</strong>: Ensure content doesn’t plagiarize or duplicate existing work.</p>



<p><strong>Accuracy</strong>: Verify facts, statistics, and claims in AI-generated content.</p>



<p><strong>Human value</strong>: Use AI to augment human creativity, not replace it entirely.</p>



<h4 class="wp-block-heading" id="responsible-ai-content-guidelines">Responsible AI Content Guidelines</h4>



<div class="sourceCode" id="cb1">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true"></a><span class="co"># Best practices for AI-generated WordPress content</span></span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true"></a></span>
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true"></a><span class="ex">1.</span> Human oversight required</span>
<span id="cb1-4"><a href="#cb1-4" aria-hidden="true"></a>   <span class="ex">-</span> Review all AI content before publishing</span>
<span id="cb1-5"><a href="#cb1-5" aria-hidden="true"></a>   <span class="ex">-</span> Edit for accuracy, tone, and brand voice</span>
<span id="cb1-6"><a href="#cb1-6" aria-hidden="true"></a>   <span class="ex">-</span> Add human expertise and insights</span>
<span id="cb1-7"><a href="#cb1-7" aria-hidden="true"></a></span>
<span id="cb1-8"><a href="#cb1-8" aria-hidden="true"></a><span class="ex">2.</span> Disclosure when appropriate</span>
<span id="cb1-9"><a href="#cb1-9" aria-hidden="true"></a>   <span class="ex">-</span> Consider adding AI disclosure for transparency</span>
<span id="cb1-10"><a href="#cb1-10" aria-hidden="true"></a>   <span class="ex">-</span> Follow FTC guidelines for automated content</span>
<span id="cb1-11"><a href="#cb1-11" aria-hidden="true"></a></span>
<span id="cb1-12"><a href="#cb1-12" aria-hidden="true"></a><span class="ex">3.</span> Quality over quantity</span>
<span id="cb1-13"><a href="#cb1-13" aria-hidden="true"></a>   <span class="ex">-</span> Don<span class="st">'t publish low-quality AI content at scale</span></span>
<span id="cb1-14"><a href="#cb1-14" aria-hidden="true"></a><span class="st">   - Maintain editorial standards</span></span>
<span id="cb1-15"><a href="#cb1-15" aria-hidden="true"></a></span>
<span id="cb1-16"><a href="#cb1-16" aria-hidden="true"></a><span class="st">4. Respect copyrights</span></span>
<span id="cb1-17"><a href="#cb1-17" aria-hidden="true"></a><span class="st">   - Don'</span>t train on or reproduce copyrighted material</span>
<span id="cb1-18"><a href="#cb1-18" aria-hidden="true"></a>   <span class="ex">-</span> Verify AI output is original</span>
<span id="cb1-19"><a href="#cb1-19" aria-hidden="true"></a></span>
<span id="cb1-20"><a href="#cb1-20" aria-hidden="true"></a><span class="ex">5.</span> Value to readers</span>
<span id="cb1-21"><a href="#cb1-21" aria-hidden="true"></a>   <span class="ex">-</span> Ensure content serves reader needs</span>
<span id="cb1-22"><a href="#cb1-22" aria-hidden="true"></a>   <span class="ex">-</span> Provide genuine value, not just SEO filler</span></code></pre>
</div>



<p>Learn about <a href="https://www.ftc.gov/business-guidance/blog/2023/02/keep-your-ai-claims-check">AI content ethics</a> from the FTC.</p>



<h3 class="wp-block-heading" id="claude-api">Claude API Integration</h3>



<p>Integrate Anthropic’s Claude API with WP-CLI for content generation.</p>



<h4 class="wp-block-heading" id="claude-api-setup">Claude API Setup</h4>



<div class="sourceCode" id="cb2">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true"></a><span class="co"># Install dependencies</span></span>
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true"></a><span class="ex">pip</span> install anthropic</span>
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true"></a></span>
<span id="cb2-4"><a href="#cb2-4" aria-hidden="true"></a><span class="co"># Set API key</span></span>
<span id="cb2-5"><a href="#cb2-5" aria-hidden="true"></a><span class="bu">export</span> <span class="va">ANTHROPIC_API_KEY=</span><span class="st">"your-api-key-here"</span></span>
<span id="cb2-6"><a href="#cb2-6" aria-hidden="true"></a></span>
<span id="cb2-7"><a href="#cb2-7" aria-hidden="true"></a><span class="co"># Test connection</span></span>
<span id="cb2-8"><a href="#cb2-8" aria-hidden="true"></a><span class="ex">python</span> -c <span class="st">"import anthropic; client = anthropic.Anthropic(); print('Connected')"</span></span></code></pre>
</div>



<h4 class="wp-block-heading" id="generate-content-with-claude">Generate Content with Claude</h4>



<div class="sourceCode" id="cb3">
<pre class="sourceCode python"><code class="sourceCode python"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true"></a><span class="co">#!/usr/bin/env python3</span></span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true"></a><span class="co"># generate-with-claude.py</span></span>
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true"></a></span>
<span id="cb3-4"><a href="#cb3-4" aria-hidden="true"></a><span class="im">import</span> anthropic</span>
<span id="cb3-5"><a href="#cb3-5" aria-hidden="true"></a><span class="im">import</span> sys</span>
<span id="cb3-6"><a href="#cb3-6" aria-hidden="true"></a><span class="im">import</span> os</span>
<span id="cb3-7"><a href="#cb3-7" aria-hidden="true"></a></span>
<span id="cb3-8"><a href="#cb3-8" aria-hidden="true"></a><span class="kw">def</span> generate_article(topic, target_words<span class="op">=</span><span class="dv">1000</span>):</span>
<span id="cb3-9"><a href="#cb3-9" aria-hidden="true"></a>    client <span class="op">=</span> anthropic.Anthropic(api_key<span class="op">=</span>os.environ.get(<span class="st">"ANTHROPIC_API_KEY"</span>))</span>
<span id="cb3-10"><a href="#cb3-10" aria-hidden="true"></a></span>
<span id="cb3-11"><a href="#cb3-11" aria-hidden="true"></a>    prompt <span class="op">=</span> <span class="ss">f"""Write a </span><span class="sc">{</span>target_words<span class="sc">}</span><span class="ss">-word informative blog post about: </span><span class="sc">{</span>topic<span class="sc">}</span></span>
<span id="cb3-12"><a href="#cb3-12" aria-hidden="true"></a></span>
<span id="cb3-13"><a href="#cb3-13" aria-hidden="true"></a><span class="ss">Include:</span></span>
<span id="cb3-14"><a href="#cb3-14" aria-hidden="true"></a><span class="ss">- Engaging introduction</span></span>
<span id="cb3-15"><a href="#cb3-15" aria-hidden="true"></a><span class="ss">- 3-5 main sections with H2 headings</span></span>
<span id="cb3-16"><a href="#cb3-16" aria-hidden="true"></a><span class="ss">- Practical examples</span></span>
<span id="cb3-17"><a href="#cb3-17" aria-hidden="true"></a><span class="ss">- Conclusion with key takeaways</span></span>
<span id="cb3-18"><a href="#cb3-18" aria-hidden="true"></a></span>
<span id="cb3-19"><a href="#cb3-19" aria-hidden="true"></a><span class="ss">Format in markdown."""</span></span>
<span id="cb3-20"><a href="#cb3-20" aria-hidden="true"></a></span>
<span id="cb3-21"><a href="#cb3-21" aria-hidden="true"></a>    message <span class="op">=</span> client.messages.create(</span>
<span id="cb3-22"><a href="#cb3-22" aria-hidden="true"></a>        model<span class="op">=</span><span class="st">"claude-3-5-sonnet-20241022"</span>,</span>
<span id="cb3-23"><a href="#cb3-23" aria-hidden="true"></a>        max_tokens<span class="op">=</span><span class="dv">4096</span>,</span>
<span id="cb3-24"><a href="#cb3-24" aria-hidden="true"></a>        messages<span class="op">=</span>[</span>
<span id="cb3-25"><a href="#cb3-25" aria-hidden="true"></a>            {<span class="st">"role"</span>: <span class="st">"user"</span>, <span class="st">"content"</span>: prompt}</span>
<span id="cb3-26"><a href="#cb3-26" aria-hidden="true"></a>        ]</span>
<span id="cb3-27"><a href="#cb3-27" aria-hidden="true"></a>    )</span>
<span id="cb3-28"><a href="#cb3-28" aria-hidden="true"></a></span>
<span id="cb3-29"><a href="#cb3-29" aria-hidden="true"></a>    <span class="cf">return</span> message.content[<span class="dv">0</span>].text</span>
<span id="cb3-30"><a href="#cb3-30" aria-hidden="true"></a></span>
<span id="cb3-31"><a href="#cb3-31" aria-hidden="true"></a><span class="cf">if</span> <span class="va">__name__</span> <span class="op">==</span> <span class="st">"__main__"</span>:</span>
<span id="cb3-32"><a href="#cb3-32" aria-hidden="true"></a>    topic <span class="op">=</span> sys.argv[<span class="dv">1</span>] <span class="cf">if</span> <span class="bu">len</span>(sys.argv) <span class="op">&gt;</span> <span class="dv">1</span> <span class="cf">else</span> <span class="st">"WordPress automation"</span></span>
<span id="cb3-33"><a href="#cb3-33" aria-hidden="true"></a></span>
<span id="cb3-34"><a href="#cb3-34" aria-hidden="true"></a>    <span class="bu">print</span>(generate_article(topic))</span></code></pre>
</div>



<p>Usage:</p>



<div class="sourceCode" id="cb4">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true"></a><span class="ex">python</span> generate-with-claude.py <span class="st">"WP-CLI best practices"</span> <span class="op">&gt;</span> article.md</span></code></pre>
</div>



<h4 class="wp-block-heading" id="publish-to-wordpress">Publish to WordPress</h4>



<div class="sourceCode" id="cb5">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true"></a><span class="co">#!/bin/bash</span></span>
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true"></a><span class="co"># ai-to-wordpress.sh - Generate and publish AI content</span></span>
<span id="cb5-3"><a href="#cb5-3" aria-hidden="true"></a></span>
<span id="cb5-4"><a href="#cb5-4" aria-hidden="true"></a><span class="va">TOPIC=</span><span class="st">"</span><span class="va">$1</span><span class="st">"</span></span>
<span id="cb5-5"><a href="#cb5-5" aria-hidden="true"></a><span class="va">CATEGORY_ID=</span><span class="st">"</span><span class="va">${2:-</span>1<span class="va">}</span><span class="st">"</span></span>
<span id="cb5-6"><a href="#cb5-6" aria-hidden="true"></a></span>
<span id="cb5-7"><a href="#cb5-7" aria-hidden="true"></a><span class="kw">if</span><span class="bu"> [</span> <span class="ot">-z</span> <span class="st">"</span><span class="va">$TOPIC</span><span class="st">"</span><span class="bu"> ]</span>; <span class="kw">then</span></span>
<span id="cb5-8"><a href="#cb5-8" aria-hidden="true"></a>    <span class="bu">echo</span> <span class="st">"Usage: </span><span class="va">$0</span><span class="st"> &lt;topic&gt; [category_id]"</span></span>
<span id="cb5-9"><a href="#cb5-9" aria-hidden="true"></a>    <span class="bu">exit</span> 1</span>
<span id="cb5-10"><a href="#cb5-10" aria-hidden="true"></a><span class="kw">fi</span></span>
<span id="cb5-11"><a href="#cb5-11" aria-hidden="true"></a></span>
<span id="cb5-12"><a href="#cb5-12" aria-hidden="true"></a><span class="bu">echo</span> <span class="st">"Generating content for: </span><span class="va">$TOPIC</span><span class="st">"</span></span>
<span id="cb5-13"><a href="#cb5-13" aria-hidden="true"></a></span>
<span id="cb5-14"><a href="#cb5-14" aria-hidden="true"></a><span class="co"># Generate content with Claude</span></span>
<span id="cb5-15"><a href="#cb5-15" aria-hidden="true"></a><span class="va">CONTENT=$(</span><span class="ex">python</span> generate-with-claude.py <span class="st">"</span><span class="va">$TOPIC</span><span class="st">"</span><span class="va">)</span></span>
<span id="cb5-16"><a href="#cb5-16" aria-hidden="true"></a></span>
<span id="cb5-17"><a href="#cb5-17" aria-hidden="true"></a><span class="co"># Create WordPress post as draft for review</span></span>
<span id="cb5-18"><a href="#cb5-18" aria-hidden="true"></a><span class="va">POST_ID=$(</span><span class="ex">wp</span> post create <span class="kw">\</span></span>
<span id="cb5-19"><a href="#cb5-19" aria-hidden="true"></a>    <span class="ex">--post_title</span>=<span class="st">"</span><span class="va">$TOPIC</span><span class="st">"</span> <span class="kw">\</span></span>
<span id="cb5-20"><a href="#cb5-20" aria-hidden="true"></a>    <span class="ex">--post_content</span>=<span class="st">"</span><span class="va">$CONTENT</span><span class="st">"</span> <span class="kw">\</span></span>
<span id="cb5-21"><a href="#cb5-21" aria-hidden="true"></a>    <span class="ex">--post_status</span>=draft <span class="kw">\</span></span>
<span id="cb5-22"><a href="#cb5-22" aria-hidden="true"></a>    <span class="ex">--post_category</span>=<span class="va">$CATEGORY_ID</span> <span class="kw">\</span></span>
<span id="cb5-23"><a href="#cb5-23" aria-hidden="true"></a>    <span class="ex">--porcelain</span><span class="va">)</span></span>
<span id="cb5-24"><a href="#cb5-24" aria-hidden="true"></a></span>
<span id="cb5-25"><a href="#cb5-25" aria-hidden="true"></a><span class="bu">echo</span> <span class="st">"✓ Draft created: Post ID </span><span class="va">$POST_ID</span><span class="st">"</span></span>
<span id="cb5-26"><a href="#cb5-26" aria-hidden="true"></a><span class="bu">echo</span> <span class="st">"Review at: </span><span class="va">$(</span><span class="ex">wp</span> option get siteurl<span class="va">)</span><span class="st">/wp-admin/post.php?post=</span><span class="va">$POST_ID</span><span class="st">&amp;action=edit"</span></span></code></pre>
</div>



<p>Learn about <a href="https://docs.anthropic.com/claude/reference/getting-started-with-the-api">Claude API</a>.</p>



<h3 class="wp-block-heading" id="openai-integration">OpenAI Integration</h3>



<p>Use OpenAI’s GPT models for WordPress content generation.</p>



<h4 class="wp-block-heading" id="openai-setup">OpenAI Setup</h4>



<div class="sourceCode" id="cb6">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true"></a><span class="co"># Install OpenAI library</span></span>
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true"></a><span class="ex">pip</span> install openai</span>
<span id="cb6-3"><a href="#cb6-3" aria-hidden="true"></a></span>
<span id="cb6-4"><a href="#cb6-4" aria-hidden="true"></a><span class="co"># Set API key</span></span>
<span id="cb6-5"><a href="#cb6-5" aria-hidden="true"></a><span class="bu">export</span> <span class="va">OPENAI_API_KEY=</span><span class="st">"your-api-key-here"</span></span></code></pre>
</div>



<h4 class="wp-block-heading" id="generate-with-gpt-4">Generate with GPT-4</h4>



<div class="sourceCode" id="cb7">
<pre class="sourceCode python"><code class="sourceCode python"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true"></a><span class="co">#!/usr/bin/env python3</span></span>
<span id="cb7-2"><a href="#cb7-2" aria-hidden="true"></a><span class="co"># generate-with-openai.py</span></span>
<span id="cb7-3"><a href="#cb7-3" aria-hidden="true"></a></span>
<span id="cb7-4"><a href="#cb7-4" aria-hidden="true"></a><span class="im">from</span> openai <span class="im">import</span> OpenAI</span>
<span id="cb7-5"><a href="#cb7-5" aria-hidden="true"></a><span class="im">import</span> sys</span>
<span id="cb7-6"><a href="#cb7-6" aria-hidden="true"></a><span class="im">import</span> os</span>
<span id="cb7-7"><a href="#cb7-7" aria-hidden="true"></a></span>
<span id="cb7-8"><a href="#cb7-8" aria-hidden="true"></a><span class="kw">def</span> generate_article(topic, model<span class="op">=</span><span class="st">"gpt-4"</span>):</span>
<span id="cb7-9"><a href="#cb7-9" aria-hidden="true"></a>    client <span class="op">=</span> OpenAI(api_key<span class="op">=</span>os.environ.get(<span class="st">"OPENAI_API_KEY"</span>))</span>
<span id="cb7-10"><a href="#cb7-10" aria-hidden="true"></a></span>
<span id="cb7-11"><a href="#cb7-11" aria-hidden="true"></a>    response <span class="op">=</span> client.chat.completions.create(</span>
<span id="cb7-12"><a href="#cb7-12" aria-hidden="true"></a>        model<span class="op">=</span>model,</span>
<span id="cb7-13"><a href="#cb7-13" aria-hidden="true"></a>        messages<span class="op">=</span>[</span>
<span id="cb7-14"><a href="#cb7-14" aria-hidden="true"></a>            {<span class="st">"role"</span>: <span class="st">"system"</span>, <span class="st">"content"</span>: <span class="st">"You are a professional content writer creating high-quality WordPress blog posts."</span>},</span>
<span id="cb7-15"><a href="#cb7-15" aria-hidden="true"></a>            {<span class="st">"role"</span>: <span class="st">"user"</span>, <span class="st">"content"</span>: <span class="ss">f"Write a comprehensive 1000-word blog post about: </span><span class="sc">{</span>topic<span class="sc">}</span><span class="ss">. Include clear headings, practical examples, and actionable takeaways. Format in markdown."</span>}</span>
<span id="cb7-16"><a href="#cb7-16" aria-hidden="true"></a>        ],</span>
<span id="cb7-17"><a href="#cb7-17" aria-hidden="true"></a>        temperature<span class="op">=</span><span class="fl">0.7</span>,</span>
<span id="cb7-18"><a href="#cb7-18" aria-hidden="true"></a>        max_tokens<span class="op">=</span><span class="dv">2000</span></span>
<span id="cb7-19"><a href="#cb7-19" aria-hidden="true"></a>    )</span>
<span id="cb7-20"><a href="#cb7-20" aria-hidden="true"></a></span>
<span id="cb7-21"><a href="#cb7-21" aria-hidden="true"></a>    <span class="cf">return</span> response.choices[<span class="dv">0</span>].message.content</span>
<span id="cb7-22"><a href="#cb7-22" aria-hidden="true"></a></span>
<span id="cb7-23"><a href="#cb7-23" aria-hidden="true"></a><span class="cf">if</span> <span class="va">__name__</span> <span class="op">==</span> <span class="st">"__main__"</span>:</span>
<span id="cb7-24"><a href="#cb7-24" aria-hidden="true"></a>    topic <span class="op">=</span> sys.argv[<span class="dv">1</span>] <span class="cf">if</span> <span class="bu">len</span>(sys.argv) <span class="op">&gt;</span> <span class="dv">1</span> <span class="cf">else</span> <span class="st">"WordPress development"</span></span>
<span id="cb7-25"><a href="#cb7-25" aria-hidden="true"></a>    <span class="bu">print</span>(generate_article(topic))</span></code></pre>
</div>



<h4 class="wp-block-heading" id="batch-content-generation">Batch Content Generation</h4>



<div class="sourceCode" id="cb8">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true"></a><span class="co">#!/bin/bash</span></span>
<span id="cb8-2"><a href="#cb8-2" aria-hidden="true"></a><span class="co"># batch-generate-content.sh - Generate multiple posts</span></span>
<span id="cb8-3"><a href="#cb8-3" aria-hidden="true"></a></span>
<span id="cb8-4"><a href="#cb8-4" aria-hidden="true"></a><span class="va">TOPICS_FILE=</span><span class="st">"</span><span class="va">$1</span><span class="st">"</span></span>
<span id="cb8-5"><a href="#cb8-5" aria-hidden="true"></a></span>
<span id="cb8-6"><a href="#cb8-6" aria-hidden="true"></a><span class="kw">if</span><span class="bu"> [</span> <span class="ot">!</span> <span class="ot">-f</span> <span class="st">"</span><span class="va">$TOPICS_FILE</span><span class="st">"</span><span class="bu"> ]</span>; <span class="kw">then</span></span>
<span id="cb8-7"><a href="#cb8-7" aria-hidden="true"></a>    <span class="bu">echo</span> <span class="st">"Usage: </span><span class="va">$0</span><span class="st"> &lt;topics-file&gt;"</span></span>
<span id="cb8-8"><a href="#cb8-8" aria-hidden="true"></a>    <span class="bu">echo</span> <span class="st">"Topics file should contain one topic per line"</span></span>
<span id="cb8-9"><a href="#cb8-9" aria-hidden="true"></a>    <span class="bu">exit</span> 1</span>
<span id="cb8-10"><a href="#cb8-10" aria-hidden="true"></a><span class="kw">fi</span></span>
<span id="cb8-11"><a href="#cb8-11" aria-hidden="true"></a></span>
<span id="cb8-12"><a href="#cb8-12" aria-hidden="true"></a><span class="kw">while</span> <span class="bu">read</span> -r <span class="va">TOPIC</span>; <span class="kw">do</span></span>
<span id="cb8-13"><a href="#cb8-13" aria-hidden="true"></a>    <span class="bu">echo</span> <span class="st">"Generating: </span><span class="va">$TOPIC</span><span class="st">"</span></span>
<span id="cb8-14"><a href="#cb8-14" aria-hidden="true"></a></span>
<span id="cb8-15"><a href="#cb8-15" aria-hidden="true"></a>    <span class="co"># Generate content</span></span>
<span id="cb8-16"><a href="#cb8-16" aria-hidden="true"></a>    <span class="va">CONTENT=$(</span><span class="ex">python</span> generate-with-claude.py <span class="st">"</span><span class="va">$TOPIC</span><span class="st">"</span><span class="va">)</span></span>
<span id="cb8-17"><a href="#cb8-17" aria-hidden="true"></a></span>
<span id="cb8-18"><a href="#cb8-18" aria-hidden="true"></a>    <span class="co"># Create draft post</span></span>
<span id="cb8-19"><a href="#cb8-19" aria-hidden="true"></a>    <span class="va">POST_ID=$(</span><span class="ex">wp</span> post create <span class="kw">\</span></span>
<span id="cb8-20"><a href="#cb8-20" aria-hidden="true"></a>        <span class="ex">--post_title</span>=<span class="st">"</span><span class="va">$TOPIC</span><span class="st">"</span> <span class="kw">\</span></span>
<span id="cb8-21"><a href="#cb8-21" aria-hidden="true"></a>        <span class="ex">--post_content</span>=<span class="st">"</span><span class="va">$CONTENT</span><span class="st">"</span> <span class="kw">\</span></span>
<span id="cb8-22"><a href="#cb8-22" aria-hidden="true"></a>        <span class="ex">--post_status</span>=draft <span class="kw">\</span></span>
<span id="cb8-23"><a href="#cb8-23" aria-hidden="true"></a>        <span class="ex">--porcelain</span><span class="va">)</span></span>
<span id="cb8-24"><a href="#cb8-24" aria-hidden="true"></a></span>
<span id="cb8-25"><a href="#cb8-25" aria-hidden="true"></a>    <span class="bu">echo</span> <span class="st">"✓ Created draft: </span><span class="va">$POST_ID</span><span class="st">"</span></span>
<span id="cb8-26"><a href="#cb8-26" aria-hidden="true"></a></span>
<span id="cb8-27"><a href="#cb8-27" aria-hidden="true"></a>    <span class="co"># Rate limiting</span></span>
<span id="cb8-28"><a href="#cb8-28" aria-hidden="true"></a>    <span class="fu">sleep</span> 2</span>
<span id="cb8-29"><a href="#cb8-29" aria-hidden="true"></a><span class="kw">done</span> <span class="op">&lt;</span> <span class="st">"</span><span class="va">$TOPICS_FILE</span><span class="st">"</span></span>
<span id="cb8-30"><a href="#cb8-30" aria-hidden="true"></a></span>
<span id="cb8-31"><a href="#cb8-31" aria-hidden="true"></a><span class="bu">echo</span> <span class="st">"✓ Batch generation complete"</span></span></code></pre>
</div>



<h3 class="wp-block-heading" id="content-enhancement">Content Enhancement</h3>



<p>Use AI to improve existing WordPress content.</p>



<h4 class="wp-block-heading" id="seo-optimization">SEO Optimization</h4>



<div class="sourceCode" id="cb9">
<pre class="sourceCode python"><code class="sourceCode python"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true"></a><span class="co">#!/usr/bin/env python3</span></span>
<span id="cb9-2"><a href="#cb9-2" aria-hidden="true"></a><span class="co"># optimize-for-seo.py</span></span>
<span id="cb9-3"><a href="#cb9-3" aria-hidden="true"></a></span>
<span id="cb9-4"><a href="#cb9-4" aria-hidden="true"></a><span class="im">import</span> anthropic</span>
<span id="cb9-5"><a href="#cb9-5" aria-hidden="true"></a><span class="im">import</span> sys</span>
<span id="cb9-6"><a href="#cb9-6" aria-hidden="true"></a><span class="im">import</span> os</span>
<span id="cb9-7"><a href="#cb9-7" aria-hidden="true"></a></span>
<span id="cb9-8"><a href="#cb9-8" aria-hidden="true"></a><span class="kw">def</span> optimize_content(original_content, focus_keyword):</span>
<span id="cb9-9"><a href="#cb9-9" aria-hidden="true"></a>    client <span class="op">=</span> anthropic.Anthropic(api_key<span class="op">=</span>os.environ.get(<span class="st">"ANTHROPIC_API_KEY"</span>))</span>
<span id="cb9-10"><a href="#cb9-10" aria-hidden="true"></a></span>
<span id="cb9-11"><a href="#cb9-11" aria-hidden="true"></a>    prompt <span class="op">=</span> <span class="ss">f"""Optimize this content for SEO targeting the keyword: </span><span class="sc">{</span>focus_keyword<span class="sc">}</span></span>
<span id="cb9-12"><a href="#cb9-12" aria-hidden="true"></a></span>
<span id="cb9-13"><a href="#cb9-13" aria-hidden="true"></a><span class="ss">Original content:</span></span>
<span id="cb9-14"><a href="#cb9-14" aria-hidden="true"></a><span class="sc">{</span>original_content<span class="sc">}</span></span>
<span id="cb9-15"><a href="#cb9-15" aria-hidden="true"></a></span>
<span id="cb9-16"><a href="#cb9-16" aria-hidden="true"></a><span class="ss">Improve:</span></span>
<span id="cb9-17"><a href="#cb9-17" aria-hidden="true"></a><span class="ss">- Keyword density (natural placement)</span></span>
<span id="cb9-18"><a href="#cb9-18" aria-hidden="true"></a><span class="ss">- Meta description suggestion</span></span>
<span id="cb9-19"><a href="#cb9-19" aria-hidden="true"></a><span class="ss">- H2/H3 headings with keyword variations</span></span>
<span id="cb9-20"><a href="#cb9-20" aria-hidden="true"></a><span class="ss">- Internal linking opportunities</span></span>
<span id="cb9-21"><a href="#cb9-21" aria-hidden="true"></a></span>
<span id="cb9-22"><a href="#cb9-22" aria-hidden="true"></a><span class="ss">Provide the optimized version."""</span></span>
<span id="cb9-23"><a href="#cb9-23" aria-hidden="true"></a></span>
<span id="cb9-24"><a href="#cb9-24" aria-hidden="true"></a>    message <span class="op">=</span> client.messages.create(</span>
<span id="cb9-25"><a href="#cb9-25" aria-hidden="true"></a>        model<span class="op">=</span><span class="st">"claude-3-5-sonnet-20241022"</span>,</span>
<span id="cb9-26"><a href="#cb9-26" aria-hidden="true"></a>        max_tokens<span class="op">=</span><span class="dv">4096</span>,</span>
<span id="cb9-27"><a href="#cb9-27" aria-hidden="true"></a>        messages<span class="op">=</span>[{<span class="st">"role"</span>: <span class="st">"user"</span>, <span class="st">"content"</span>: prompt}]</span>
<span id="cb9-28"><a href="#cb9-28" aria-hidden="true"></a>    )</span>
<span id="cb9-29"><a href="#cb9-29" aria-hidden="true"></a></span>
<span id="cb9-30"><a href="#cb9-30" aria-hidden="true"></a>    <span class="cf">return</span> message.content[<span class="dv">0</span>].text</span>
<span id="cb9-31"><a href="#cb9-31" aria-hidden="true"></a></span>
<span id="cb9-32"><a href="#cb9-32" aria-hidden="true"></a><span class="cf">if</span> <span class="va">__name__</span> <span class="op">==</span> <span class="st">"__main__"</span>:</span>
<span id="cb9-33"><a href="#cb9-33" aria-hidden="true"></a>    <span class="cf">if</span> <span class="bu">len</span>(sys.argv) <span class="op">&lt;</span> <span class="dv">3</span>:</span>
<span id="cb9-34"><a href="#cb9-34" aria-hidden="true"></a>        <span class="bu">print</span>(<span class="st">"Usage: optimize-for-seo.py &lt;post_id&gt; &lt;focus_keyword&gt;"</span>)</span>
<span id="cb9-35"><a href="#cb9-35" aria-hidden="true"></a>        sys.exit(<span class="dv">1</span>)</span>
<span id="cb9-36"><a href="#cb9-36" aria-hidden="true"></a></span>
<span id="cb9-37"><a href="#cb9-37" aria-hidden="true"></a>    post_id <span class="op">=</span> sys.argv[<span class="dv">1</span>]</span>
<span id="cb9-38"><a href="#cb9-38" aria-hidden="true"></a>    keyword <span class="op">=</span> sys.argv[<span class="dv">2</span>]</span>
<span id="cb9-39"><a href="#cb9-39" aria-hidden="true"></a></span>
<span id="cb9-40"><a href="#cb9-40" aria-hidden="true"></a>    <span class="co"># Get original content (would use wp-cli here)</span></span>
<span id="cb9-41"><a href="#cb9-41" aria-hidden="true"></a>    content <span class="op">=</span> sys.stdin.read()</span>
<span id="cb9-42"><a href="#cb9-42" aria-hidden="true"></a></span>
<span id="cb9-43"><a href="#cb9-43" aria-hidden="true"></a>    <span class="bu">print</span>(optimize_content(content, keyword))</span></code></pre>
</div>



<h4 class="wp-block-heading" id="content-expansion">Content Expansion</h4>



<div class="sourceCode" id="cb10">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true"></a><span class="co">#!/bin/bash</span></span>
<span id="cb10-2"><a href="#cb10-2" aria-hidden="true"></a><span class="co"># expand-content.sh - Expand short posts with AI</span></span>
<span id="cb10-3"><a href="#cb10-3" aria-hidden="true"></a></span>
<span id="cb10-4"><a href="#cb10-4" aria-hidden="true"></a><span class="va">MIN_WORDS=</span>300</span>
<span id="cb10-5"><a href="#cb10-5" aria-hidden="true"></a><span class="va">TARGET_WORDS=</span>1000</span>
<span id="cb10-6"><a href="#cb10-6" aria-hidden="true"></a></span>
<span id="cb10-7"><a href="#cb10-7" aria-hidden="true"></a><span class="co"># Find short posts</span></span>
<span id="cb10-8"><a href="#cb10-8" aria-hidden="true"></a><span class="va">SHORT_POSTS=$(</span><span class="ex">wp</span> post list <span class="kw">\</span></span>
<span id="cb10-9"><a href="#cb10-9" aria-hidden="true"></a>    <span class="ex">--post_status</span>=publish <span class="kw">\</span></span>
<span id="cb10-10"><a href="#cb10-10" aria-hidden="true"></a>    <span class="ex">--format</span>=ids <span class="kw">\</span></span>
<span id="cb10-11"><a href="#cb10-11" aria-hidden="true"></a>    <span class="ex">--fields</span>=ID,post_content <span class="kw">\</span></span>
<span id="cb10-12"><a href="#cb10-12" aria-hidden="true"></a>    <span class="kw">|</span> <span class="kw">while</span> <span class="bu">read</span> <span class="va">POST_ID</span>; <span class="kw">do</span></span>
<span id="cb10-13"><a href="#cb10-13" aria-hidden="true"></a>        <span class="va">WORD_COUNT=$(</span><span class="ex">wp</span> post get <span class="va">$POST_ID</span> --field=post_content <span class="kw">|</span> <span class="fu">wc</span> -w<span class="va">)</span></span>
<span id="cb10-14"><a href="#cb10-14" aria-hidden="true"></a>        <span class="kw">if</span><span class="bu"> [</span> <span class="st">"</span><span class="va">$WORD_COUNT</span><span class="st">"</span> <span class="ot">-lt</span> <span class="st">"</span><span class="va">$MIN_WORDS</span><span class="st">"</span><span class="bu"> ]</span>; <span class="kw">then</span></span>
<span id="cb10-15"><a href="#cb10-15" aria-hidden="true"></a>            <span class="bu">echo</span> <span class="st">"</span><span class="va">$POST_ID</span><span class="st">"</span></span>
<span id="cb10-16"><a href="#cb10-16" aria-hidden="true"></a>        <span class="kw">fi</span></span>
<span id="cb10-17"><a href="#cb10-17" aria-hidden="true"></a>    <span class="kw">done</span><span class="va">)</span></span>
<span id="cb10-18"><a href="#cb10-18" aria-hidden="true"></a></span>
<span id="cb10-19"><a href="#cb10-19" aria-hidden="true"></a><span class="kw">for</span> <span class="ex">POST_ID</span> in <span class="va">$SHORT_POSTS</span><span class="kw">;</span> <span class="kw">do</span></span>
<span id="cb10-20"><a href="#cb10-20" aria-hidden="true"></a>    <span class="bu">echo</span> <span class="st">"Expanding post: </span><span class="va">$POST_ID</span><span class="st">"</span></span>
<span id="cb10-21"><a href="#cb10-21" aria-hidden="true"></a></span>
<span id="cb10-22"><a href="#cb10-22" aria-hidden="true"></a>    <span class="va">TITLE=$(</span><span class="ex">wp</span> post get <span class="va">$POST_ID</span> --field=post_title<span class="va">)</span></span>
<span id="cb10-23"><a href="#cb10-23" aria-hidden="true"></a>    <span class="va">CONTENT=$(</span><span class="ex">wp</span> post get <span class="va">$POST_ID</span> --field=post_content<span class="va">)</span></span>
<span id="cb10-24"><a href="#cb10-24" aria-hidden="true"></a></span>
<span id="cb10-25"><a href="#cb10-25" aria-hidden="true"></a>    <span class="co"># Generate expanded version</span></span>
<span id="cb10-26"><a href="#cb10-26" aria-hidden="true"></a>    <span class="va">EXPANDED=$(</span><span class="ex">python</span> -c <span class="st">"</span></span>
<span id="cb10-27"><a href="#cb10-27" aria-hidden="true"></a><span class="st">import anthropic, os</span></span>
<span id="cb10-28"><a href="#cb10-28" aria-hidden="true"></a><span class="st">client = anthropic.Anthropic(api_key=os.environ.get('ANTHROPIC_API_KEY'))</span></span>
<span id="cb10-29"><a href="#cb10-29" aria-hidden="true"></a><span class="st">message = client.messages.create(</span></span>
<span id="cb10-30"><a href="#cb10-30" aria-hidden="true"></a><span class="st">    model='claude-3-5-sonnet-20241022',</span></span>
<span id="cb10-31"><a href="#cb10-31" aria-hidden="true"></a><span class="st">    max_tokens=2048,</span></span>
<span id="cb10-32"><a href="#cb10-32" aria-hidden="true"></a><span class="st">    messages=[{</span></span>
<span id="cb10-33"><a href="#cb10-33" aria-hidden="true"></a><span class="st">        'role': 'user',</span></span>
<span id="cb10-34"><a href="#cb10-34" aria-hidden="true"></a><span class="st">        'content': f'''Expand this article to approximately </span><span class="va">$TARGET_WORDS</span><span class="st"> words while maintaining quality:</span></span>
<span id="cb10-35"><a href="#cb10-35" aria-hidden="true"></a></span>
<span id="cb10-36"><a href="#cb10-36" aria-hidden="true"></a><span class="st">Title: </span><span class="va">$TITLE</span></span>
<span id="cb10-37"><a href="#cb10-37" aria-hidden="true"></a></span>
<span id="cb10-38"><a href="#cb10-38" aria-hidden="true"></a><span class="st">Current content:</span></span>
<span id="cb10-39"><a href="#cb10-39" aria-hidden="true"></a><span class="va">$CONTENT</span></span>
<span id="cb10-40"><a href="#cb10-40" aria-hidden="true"></a></span>
<span id="cb10-41"><a href="#cb10-41" aria-hidden="true"></a><span class="st">Add more detail, examples, and value while staying on topic.'''</span></span>
<span id="cb10-42"><a href="#cb10-42" aria-hidden="true"></a><span class="st">    }]</span></span>
<span id="cb10-43"><a href="#cb10-43" aria-hidden="true"></a><span class="st">)</span></span>
<span id="cb10-44"><a href="#cb10-44" aria-hidden="true"></a><span class="st">print(message.content[0].text)</span></span>
<span id="cb10-45"><a href="#cb10-45" aria-hidden="true"></a><span class="st">"</span><span class="va">)</span></span>
<span id="cb10-46"><a href="#cb10-46" aria-hidden="true"></a></span>
<span id="cb10-47"><a href="#cb10-47" aria-hidden="true"></a>    <span class="co"># Save as revision (create new draft for review)</span></span>
<span id="cb10-48"><a href="#cb10-48" aria-hidden="true"></a>    <span class="ex">wp</span> post create <span class="kw">\</span></span>
<span id="cb10-49"><a href="#cb10-49" aria-hidden="true"></a>        <span class="ex">--post_title</span>=<span class="st">"</span><span class="va">$TITLE</span><span class="st"> (Expanded)"</span> <span class="kw">\</span></span>
<span id="cb10-50"><a href="#cb10-50" aria-hidden="true"></a>        <span class="ex">--post_content</span>=<span class="st">"</span><span class="va">$EXPANDED</span><span class="st">"</span> <span class="kw">\</span></span>
<span id="cb10-51"><a href="#cb10-51" aria-hidden="true"></a>        <span class="ex">--post_status</span>=draft</span>
<span id="cb10-52"><a href="#cb10-52" aria-hidden="true"></a></span>
<span id="cb10-53"><a href="#cb10-53" aria-hidden="true"></a>    <span class="bu">echo</span> <span class="st">"✓ Expanded version created for review"</span></span>
<span id="cb10-54"><a href="#cb10-54" aria-hidden="true"></a><span class="kw">done</span></span></code></pre>
</div>



<h3 class="wp-block-heading" id="automated-workflows">Automated Publishing Workflows</h3>



<p>Build complete AI-powered content pipelines.</p>



<h4 class="wp-block-heading" id="daily-auto-publish-system">Daily Auto-Publish System</h4>



<div class="sourceCode" id="cb11">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true"></a><span class="co">#!/bin/bash</span></span>
<span id="cb11-2"><a href="#cb11-2" aria-hidden="true"></a><span class="co"># daily-ai-content.sh - Generate and publish content daily</span></span>
<span id="cb11-3"><a href="#cb11-3" aria-hidden="true"></a></span>
<span id="cb11-4"><a href="#cb11-4" aria-hidden="true"></a><span class="va">TOPICS=(</span></span>
<span id="cb11-5"><a href="#cb11-5" aria-hidden="true"></a>    <span class="st">"WordPress security best practices"</span></span>
<span id="cb11-6"><a href="#cb11-6" aria-hidden="true"></a>    <span class="st">"WP-CLI productivity tips"</span></span>
<span id="cb11-7"><a href="#cb11-7" aria-hidden="true"></a>    <span class="st">"WordPress performance optimization"</span></span>
<span id="cb11-8"><a href="#cb11-8" aria-hidden="true"></a>    <span class="st">"Content management automation"</span></span>
<span id="cb11-9"><a href="#cb11-9" aria-hidden="true"></a>)</span>
<span id="cb11-10"><a href="#cb11-10" aria-hidden="true"></a></span>
<span id="cb11-11"><a href="#cb11-11" aria-hidden="true"></a><span class="co"># Select random topic</span></span>
<span id="cb11-12"><a href="#cb11-12" aria-hidden="true"></a><span class="va">TOPIC=</span><span class="st">"</span><span class="va">${TOPICS[$RANDOM % ${#TOPICS[@]}]}</span><span class="st">"</span></span>
<span id="cb11-13"><a href="#cb11-13" aria-hidden="true"></a></span>
<span id="cb11-14"><a href="#cb11-14" aria-hidden="true"></a><span class="bu">echo</span> <span class="st">"Generating daily content: </span><span class="va">$TOPIC</span><span class="st">"</span></span>
<span id="cb11-15"><a href="#cb11-15" aria-hidden="true"></a></span>
<span id="cb11-16"><a href="#cb11-16" aria-hidden="true"></a><span class="co"># Generate with AI</span></span>
<span id="cb11-17"><a href="#cb11-17" aria-hidden="true"></a><span class="va">CONTENT=$(</span><span class="ex">python</span> generate-with-claude.py <span class="st">"</span><span class="va">$TOPIC</span><span class="st">"</span><span class="va">)</span></span>
<span id="cb11-18"><a href="#cb11-18" aria-hidden="true"></a></span>
<span id="cb11-19"><a href="#cb11-19" aria-hidden="true"></a><span class="co"># Add disclaimer</span></span>
<span id="cb11-20"><a href="#cb11-20" aria-hidden="true"></a><span class="va">DISCLAIMER=</span><span class="st">"&lt;em&gt;Note: This article was generated with AI assistance and reviewed by our editorial team.&lt;/em&gt;"</span></span>
<span id="cb11-21"><a href="#cb11-21" aria-hidden="true"></a></span>
<span id="cb11-22"><a href="#cb11-22" aria-hidden="true"></a><span class="va">FULL_CONTENT=</span><span class="st">"</span><span class="va">${CONTENT}</span></span>
<span id="cb11-23"><a href="#cb11-23" aria-hidden="true"></a></span>
<span id="cb11-24"><a href="#cb11-24" aria-hidden="true"></a></span>
<span id="cb11-25"><a href="#cb11-25" aria-hidden="true"></a><span class="va">${DISCLAIMER}</span><span class="st">"</span></span>
<span id="cb11-26"><a href="#cb11-26" aria-hidden="true"></a></span>
<span id="cb11-27"><a href="#cb11-27" aria-hidden="true"></a><span class="co"># Create post</span></span>
<span id="cb11-28"><a href="#cb11-28" aria-hidden="true"></a><span class="va">POST_ID=$(</span><span class="ex">wp</span> post create <span class="kw">\</span></span>
<span id="cb11-29"><a href="#cb11-29" aria-hidden="true"></a>    <span class="ex">--post_title</span>=<span class="st">"</span><span class="va">$TOPIC</span><span class="st">"</span> <span class="kw">\</span></span>
<span id="cb11-30"><a href="#cb11-30" aria-hidden="true"></a>    <span class="ex">--post_content</span>=<span class="st">"</span><span class="va">$FULL_CONTENT</span><span class="st">"</span> <span class="kw">\</span></span>
<span id="cb11-31"><a href="#cb11-31" aria-hidden="true"></a>    <span class="ex">--post_status</span>=draft <span class="kw">\</span></span>
<span id="cb11-32"><a href="#cb11-32" aria-hidden="true"></a>    <span class="ex">--post_category</span>=5 <span class="kw">\</span></span>
<span id="cb11-33"><a href="#cb11-33" aria-hidden="true"></a>    <span class="ex">--tags_input</span>=<span class="st">"ai-generated,automation"</span> <span class="kw">\</span></span>
<span id="cb11-34"><a href="#cb11-34" aria-hidden="true"></a>    <span class="ex">--porcelain</span><span class="va">)</span></span>
<span id="cb11-35"><a href="#cb11-35" aria-hidden="true"></a></span>
<span id="cb11-36"><a href="#cb11-36" aria-hidden="true"></a><span class="co"># Set featured image (from Unsplash API - separate integration)</span></span>
<span id="cb11-37"><a href="#cb11-37" aria-hidden="true"></a><span class="co"># Add meta fields for tracking</span></span>
<span id="cb11-38"><a href="#cb11-38" aria-hidden="true"></a><span class="ex">wp</span> post meta add <span class="va">$POST_ID</span> ai_generated <span class="st">"true"</span></span>
<span id="cb11-39"><a href="#cb11-39" aria-hidden="true"></a><span class="ex">wp</span> post meta add <span class="va">$POST_ID</span> generation_date <span class="st">"</span><span class="va">$(</span><span class="fu">date</span> +%Y-%m-%d<span class="va">)</span><span class="st">"</span></span>
<span id="cb11-40"><a href="#cb11-40" aria-hidden="true"></a></span>
<span id="cb11-41"><a href="#cb11-41" aria-hidden="true"></a><span class="bu">echo</span> <span class="st">"✓ Draft created: </span><span class="va">$POST_ID</span><span class="st">"</span></span>
<span id="cb11-42"><a href="#cb11-42" aria-hidden="true"></a><span class="bu">echo</span> <span class="st">"Review and publish at: </span><span class="va">$(</span><span class="ex">wp</span> option get siteurl<span class="va">)</span><span class="st">/wp-admin/post.php?post=</span><span class="va">$POST_ID</span><span class="st">&amp;action=edit"</span></span></code></pre>
</div>



<p>Schedule with cron:</p>



<div class="sourceCode" id="cb12">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true"></a><span class="co"># Run daily at 8 AM</span></span>
<span id="cb12-2"><a href="#cb12-2" aria-hidden="true"></a><span class="ex">0</span> 8 * * * /usr/local/bin/daily-ai-content.sh</span></code></pre>
</div>



<h4 class="wp-block-heading" id="content-translation">Content Translation</h4>



<div class="sourceCode" id="cb13">
<pre class="sourceCode python"><code class="sourceCode python"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true"></a><span class="co">#!/usr/bin/env python3</span></span>
<span id="cb13-2"><a href="#cb13-2" aria-hidden="true"></a><span class="co"># translate-post.py - Translate WordPress posts with AI</span></span>
<span id="cb13-3"><a href="#cb13-3" aria-hidden="true"></a></span>
<span id="cb13-4"><a href="#cb13-4" aria-hidden="true"></a><span class="im">import</span> anthropic</span>
<span id="cb13-5"><a href="#cb13-5" aria-hidden="true"></a><span class="im">import</span> sys</span>
<span id="cb13-6"><a href="#cb13-6" aria-hidden="true"></a><span class="im">import</span> os</span>
<span id="cb13-7"><a href="#cb13-7" aria-hidden="true"></a></span>
<span id="cb13-8"><a href="#cb13-8" aria-hidden="true"></a><span class="kw">def</span> translate_content(content, target_language):</span>
<span id="cb13-9"><a href="#cb13-9" aria-hidden="true"></a>    client <span class="op">=</span> anthropic.Anthropic(api_key<span class="op">=</span>os.environ.get(<span class="st">"ANTHROPIC_API_KEY"</span>))</span>
<span id="cb13-10"><a href="#cb13-10" aria-hidden="true"></a></span>
<span id="cb13-11"><a href="#cb13-11" aria-hidden="true"></a>    message <span class="op">=</span> client.messages.create(</span>
<span id="cb13-12"><a href="#cb13-12" aria-hidden="true"></a>        model<span class="op">=</span><span class="st">"claude-3-5-sonnet-20241022"</span>,</span>
<span id="cb13-13"><a href="#cb13-13" aria-hidden="true"></a>        max_tokens<span class="op">=</span><span class="dv">4096</span>,</span>
<span id="cb13-14"><a href="#cb13-14" aria-hidden="true"></a>        messages<span class="op">=</span>[{</span>
<span id="cb13-15"><a href="#cb13-15" aria-hidden="true"></a>            <span class="st">"role"</span>: <span class="st">"user"</span>,</span>
<span id="cb13-16"><a href="#cb13-16" aria-hidden="true"></a>            <span class="st">"content"</span>: <span class="ss">f"Translate this content to </span><span class="sc">{</span>target_language<span class="sc">}</span><span class="ss">. Maintain formatting and structure:</span><span class="ch">\n\n</span><span class="sc">{</span>content<span class="sc">}</span><span class="ss">"</span></span>
<span id="cb13-17"><a href="#cb13-17" aria-hidden="true"></a>        }]</span>
<span id="cb13-18"><a href="#cb13-18" aria-hidden="true"></a>    )</span>
<span id="cb13-19"><a href="#cb13-19" aria-hidden="true"></a></span>
<span id="cb13-20"><a href="#cb13-20" aria-hidden="true"></a>    <span class="cf">return</span> message.content[<span class="dv">0</span>].text</span>
<span id="cb13-21"><a href="#cb13-21" aria-hidden="true"></a></span>
<span id="cb13-22"><a href="#cb13-22" aria-hidden="true"></a><span class="cf">if</span> <span class="va">__name__</span> <span class="op">==</span> <span class="st">"__main__"</span>:</span>
<span id="cb13-23"><a href="#cb13-23" aria-hidden="true"></a>    <span class="cf">if</span> <span class="bu">len</span>(sys.argv) <span class="op">&lt;</span> <span class="dv">3</span>:</span>
<span id="cb13-24"><a href="#cb13-24" aria-hidden="true"></a>        <span class="bu">print</span>(<span class="st">"Usage: translate-post.py &lt;post_id&gt; &lt;language&gt;"</span>)</span>
<span id="cb13-25"><a href="#cb13-25" aria-hidden="true"></a>        sys.exit(<span class="dv">1</span>)</span>
<span id="cb13-26"><a href="#cb13-26" aria-hidden="true"></a></span>
<span id="cb13-27"><a href="#cb13-27" aria-hidden="true"></a>    post_id <span class="op">=</span> sys.argv[<span class="dv">1</span>]</span>
<span id="cb13-28"><a href="#cb13-28" aria-hidden="true"></a>    language <span class="op">=</span> sys.argv[<span class="dv">2</span>]</span>
<span id="cb13-29"><a href="#cb13-29" aria-hidden="true"></a></span>
<span id="cb13-30"><a href="#cb13-30" aria-hidden="true"></a>    <span class="co"># Read from stdin</span></span>
<span id="cb13-31"><a href="#cb13-31" aria-hidden="true"></a>    content <span class="op">=</span> sys.stdin.read()</span>
<span id="cb13-32"><a href="#cb13-32" aria-hidden="true"></a></span>
<span id="cb13-33"><a href="#cb13-33" aria-hidden="true"></a>    <span class="bu">print</span>(translate_content(content, language))</span></code></pre>
</div>



<p>Usage:</p>



<div class="sourceCode" id="cb14">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true"></a><span class="co"># Translate post to Spanish</span></span>
<span id="cb14-2"><a href="#cb14-2" aria-hidden="true"></a><span class="ex">wp</span> post get 123 --field=post_content <span class="kw">|</span> <span class="ex">python</span> translate-post.py 123 <span class="st">"Spanish"</span> <span class="kw">|</span> <span class="kw">\</span></span>
<span id="cb14-3"><a href="#cb14-3" aria-hidden="true"></a><span class="ex">wp</span> post create --post_title=<span class="st">"Translated Post"</span> --post_content=-</span></code></pre>
</div>



<h3 class="wp-block-heading" id="quality-control">Quality Control</h3>



<p>Implement checks to ensure AI content quality.</p>



<h4 class="wp-block-heading" id="content-review-checklist">Content Review Checklist</h4>



<div class="sourceCode" id="cb15">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true"></a><span class="co">#!/bin/bash</span></span>
<span id="cb15-2"><a href="#cb15-2" aria-hidden="true"></a><span class="co"># review-ai-content.sh - Quality check for AI posts</span></span>
<span id="cb15-3"><a href="#cb15-3" aria-hidden="true"></a></span>
<span id="cb15-4"><a href="#cb15-4" aria-hidden="true"></a><span class="va">POST_ID=</span><span class="st">"</span><span class="va">$1</span><span class="st">"</span></span>
<span id="cb15-5"><a href="#cb15-5" aria-hidden="true"></a></span>
<span id="cb15-6"><a href="#cb15-6" aria-hidden="true"></a><span class="bu">echo</span> <span class="st">"Reviewing AI-generated post: </span><span class="va">$POST_ID</span><span class="st">"</span></span>
<span id="cb15-7"><a href="#cb15-7" aria-hidden="true"></a></span>
<span id="cb15-8"><a href="#cb15-8" aria-hidden="true"></a><span class="co"># Check word count</span></span>
<span id="cb15-9"><a href="#cb15-9" aria-hidden="true"></a><span class="va">WORD_COUNT=$(</span><span class="ex">wp</span> post get <span class="va">$POST_ID</span> --field=post_content <span class="kw">|</span> <span class="fu">wc</span> -w<span class="va">)</span></span>
<span id="cb15-10"><a href="#cb15-10" aria-hidden="true"></a><span class="bu">echo</span> <span class="st">"Word count: </span><span class="va">$WORD_COUNT</span><span class="st">"</span></span>
<span id="cb15-11"><a href="#cb15-11" aria-hidden="true"></a></span>
<span id="cb15-12"><a href="#cb15-12" aria-hidden="true"></a><span class="kw">if</span><span class="bu"> [</span> <span class="st">"</span><span class="va">$WORD_COUNT</span><span class="st">"</span> <span class="ot">-lt</span> 300<span class="bu"> ]</span>; <span class="kw">then</span></span>
<span id="cb15-13"><a href="#cb15-13" aria-hidden="true"></a>    <span class="bu">echo</span> <span class="st">"⚠ Content too short"</span></span>
<span id="cb15-14"><a href="#cb15-14" aria-hidden="true"></a><span class="kw">fi</span></span>
<span id="cb15-15"><a href="#cb15-15" aria-hidden="true"></a></span>
<span id="cb15-16"><a href="#cb15-16" aria-hidden="true"></a><span class="co"># Check for common AI phrases</span></span>
<span id="cb15-17"><a href="#cb15-17" aria-hidden="true"></a><span class="va">CONTENT=$(</span><span class="ex">wp</span> post get <span class="va">$POST_ID</span> --field=post_content<span class="va">)</span></span>
<span id="cb15-18"><a href="#cb15-18" aria-hidden="true"></a></span>
<span id="cb15-19"><a href="#cb15-19" aria-hidden="true"></a><span class="va">AI_PHRASES=(</span></span>
<span id="cb15-20"><a href="#cb15-20" aria-hidden="true"></a>    <span class="st">"as an AI"</span></span>
<span id="cb15-21"><a href="#cb15-21" aria-hidden="true"></a>    <span class="st">"I don't have"</span></span>
<span id="cb15-22"><a href="#cb15-22" aria-hidden="true"></a>    <span class="st">"I cannot"</span></span>
<span id="cb15-23"><a href="#cb15-23" aria-hidden="true"></a>    <span class="st">"my knowledge cutoff"</span></span>
<span id="cb15-24"><a href="#cb15-24" aria-hidden="true"></a>)</span>
<span id="cb15-25"><a href="#cb15-25" aria-hidden="true"></a></span>
<span id="cb15-26"><a href="#cb15-26" aria-hidden="true"></a><span class="kw">for</span> <span class="ex">PHRASE</span> in <span class="st">"</span><span class="va">${AI_PHRASES[@]}</span><span class="st">"</span><span class="kw">;</span> <span class="kw">do</span></span>
<span id="cb15-27"><a href="#cb15-27" aria-hidden="true"></a>    <span class="kw">if</span> <span class="bu">echo</span> <span class="st">"</span><span class="va">$CONTENT</span><span class="st">"</span> <span class="kw">|</span> <span class="fu">grep</span> -qi <span class="st">"</span><span class="va">$PHRASE</span><span class="st">"</span><span class="kw">;</span> <span class="kw">then</span></span>
<span id="cb15-28"><a href="#cb15-28" aria-hidden="true"></a>        <span class="bu">echo</span> <span class="st">"⚠ Found AI artifact: '</span><span class="va">$PHRASE</span><span class="st">'"</span></span>
<span id="cb15-29"><a href="#cb15-29" aria-hidden="true"></a>    <span class="kw">fi</span></span>
<span id="cb15-30"><a href="#cb15-30" aria-hidden="true"></a><span class="kw">done</span></span>
<span id="cb15-31"><a href="#cb15-31" aria-hidden="true"></a></span>
<span id="cb15-32"><a href="#cb15-32" aria-hidden="true"></a><span class="co"># Check readability</span></span>
<span id="cb15-33"><a href="#cb15-33" aria-hidden="true"></a><span class="va">TITLE=$(</span><span class="ex">wp</span> post get <span class="va">$POST_ID</span> --field=post_title<span class="va">)</span></span>
<span id="cb15-34"><a href="#cb15-34" aria-hidden="true"></a><span class="kw">if</span><span class="bu"> [</span> <span class="va">${#TITLE}</span> <span class="ot">-gt</span> 60<span class="bu"> ]</span>; <span class="kw">then</span></span>
<span id="cb15-35"><a href="#cb15-35" aria-hidden="true"></a>    <span class="bu">echo</span> <span class="st">"⚠ Title too long for SEO"</span></span>
<span id="cb15-36"><a href="#cb15-36" aria-hidden="true"></a><span class="kw">fi</span></span>
<span id="cb15-37"><a href="#cb15-37" aria-hidden="true"></a></span>
<span id="cb15-38"><a href="#cb15-38" aria-hidden="true"></a><span class="co"># Check for images</span></span>
<span id="cb15-39"><a href="#cb15-39" aria-hidden="true"></a><span class="va">IMAGE_COUNT=$(</span><span class="bu">echo</span> <span class="st">"</span><span class="va">$CONTENT</span><span class="st">"</span> <span class="kw">|</span> <span class="fu">grep</span> -c <span class="st">'&lt;img'</span><span class="va">)</span></span>
<span id="cb15-40"><a href="#cb15-40" aria-hidden="true"></a><span class="kw">if</span><span class="bu"> [</span> <span class="st">"</span><span class="va">$IMAGE_COUNT</span><span class="st">"</span> <span class="ot">-eq</span> 0<span class="bu"> ]</span>; <span class="kw">then</span></span>
<span id="cb15-41"><a href="#cb15-41" aria-hidden="true"></a>    <span class="bu">echo</span> <span class="st">"⚠ No images in content"</span></span>
<span id="cb15-42"><a href="#cb15-42" aria-hidden="true"></a><span class="kw">fi</span></span>
<span id="cb15-43"><a href="#cb15-43" aria-hidden="true"></a></span>
<span id="cb15-44"><a href="#cb15-44" aria-hidden="true"></a><span class="bu">echo</span> <span class="st">"✓ Review complete"</span></span></code></pre>
</div>



<h3 class="wp-block-heading" id="cost-management">Cost Management</h3>



<p>Track and control AI API costs.</p>



<h4 class="wp-block-heading" id="api-usage-tracking">API Usage Tracking</h4>



<div class="sourceCode" id="cb16">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb16-1"><a href="#cb16-1" aria-hidden="true"></a><span class="co">#!/bin/bash</span></span>
<span id="cb16-2"><a href="#cb16-2" aria-hidden="true"></a><span class="co"># track-ai-costs.sh</span></span>
<span id="cb16-3"><a href="#cb16-3" aria-hidden="true"></a></span>
<span id="cb16-4"><a href="#cb16-4" aria-hidden="true"></a><span class="va">LOG_FILE=</span><span class="st">"/var/log/ai-content-costs.log"</span></span>
<span id="cb16-5"><a href="#cb16-5" aria-hidden="true"></a></span>
<span id="cb16-6"><a href="#cb16-6" aria-hidden="true"></a><span class="fu">log_generation()</span> <span class="kw">{</span></span>
<span id="cb16-7"><a href="#cb16-7" aria-hidden="true"></a>    <span class="bu">local</span> <span class="va">model=</span><span class="st">"</span><span class="va">$1</span><span class="st">"</span></span>
<span id="cb16-8"><a href="#cb16-8" aria-hidden="true"></a>    <span class="bu">local</span> <span class="va">tokens=</span><span class="st">"</span><span class="va">$2</span><span class="st">"</span></span>
<span id="cb16-9"><a href="#cb16-9" aria-hidden="true"></a>    <span class="bu">local</span> <span class="va">cost=</span><span class="st">"</span><span class="va">$3</span><span class="st">"</span></span>
<span id="cb16-10"><a href="#cb16-10" aria-hidden="true"></a></span>
<span id="cb16-11"><a href="#cb16-11" aria-hidden="true"></a>    <span class="bu">echo</span> <span class="st">"</span><span class="va">$(</span><span class="fu">date</span> +%Y-%m-%d<span class="va">)</span><span class="st">,</span><span class="va">$(</span><span class="fu">date</span> +%H:%M:%S<span class="va">)</span><span class="st">,</span><span class="va">$model</span><span class="st">,</span><span class="va">$tokens</span><span class="st">,</span><span class="va">$cost</span><span class="st">"</span> <span class="op">&gt;&gt;</span> <span class="st">"</span><span class="va">$LOG_FILE</span><span class="st">"</span></span>
<span id="cb16-12"><a href="#cb16-12" aria-hidden="true"></a><span class="kw">}</span></span>
<span id="cb16-13"><a href="#cb16-13" aria-hidden="true"></a></span>
<span id="cb16-14"><a href="#cb16-14" aria-hidden="true"></a><span class="co"># After each generation</span></span>
<span id="cb16-15"><a href="#cb16-15" aria-hidden="true"></a><span class="ex">log_generation</span> <span class="st">"claude-3-sonnet"</span> <span class="st">"2048"</span> <span class="st">"0.06"</span></span>
<span id="cb16-16"><a href="#cb16-16" aria-hidden="true"></a></span>
<span id="cb16-17"><a href="#cb16-17" aria-hidden="true"></a><span class="co"># Monthly report</span></span>
<span id="cb16-18"><a href="#cb16-18" aria-hidden="true"></a><span class="fu">generate_cost_report()</span> <span class="kw">{</span></span>
<span id="cb16-19"><a href="#cb16-19" aria-hidden="true"></a>    <span class="bu">echo</span> <span class="st">"AI Content Generation Cost Report"</span></span>
<span id="cb16-20"><a href="#cb16-20" aria-hidden="true"></a>    <span class="bu">echo</span> <span class="st">"Month: </span><span class="va">$(</span><span class="fu">date</span> +%Y-%m<span class="va">)</span><span class="st">"</span></span>
<span id="cb16-21"><a href="#cb16-21" aria-hidden="true"></a>    <span class="bu">echo</span> <span class="st">"=================================="</span></span>
<span id="cb16-22"><a href="#cb16-22" aria-hidden="true"></a></span>
<span id="cb16-23"><a href="#cb16-23" aria-hidden="true"></a>    <span class="va">TOTAL_COST=$(</span><span class="fu">awk</span> -F<span class="st">','</span> <span class="st">'{sum += $5} END {print sum}'</span> <span class="st">"</span><span class="va">$LOG_FILE</span><span class="st">"</span><span class="va">)</span></span>
<span id="cb16-24"><a href="#cb16-24" aria-hidden="true"></a>    <span class="va">TOTAL_POSTS=$(</span><span class="fu">wc</span> -l <span class="op">&lt;</span> <span class="st">"</span><span class="va">$LOG_FILE</span><span class="st">"</span><span class="va">)</span></span>
<span id="cb16-25"><a href="#cb16-25" aria-hidden="true"></a></span>
<span id="cb16-26"><a href="#cb16-26" aria-hidden="true"></a>    <span class="bu">echo</span> <span class="st">"Total generations: </span><span class="va">$TOTAL_POSTS</span><span class="st">"</span></span>
<span id="cb16-27"><a href="#cb16-27" aria-hidden="true"></a>    <span class="bu">echo</span> <span class="st">"Total cost: </span><span class="dt">\$</span><span class="va">$TOTAL_COST</span><span class="st">"</span></span>
<span id="cb16-28"><a href="#cb16-28" aria-hidden="true"></a>    <span class="bu">echo</span> <span class="st">"Average per post: </span><span class="dt">\$</span><span class="va">$(</span><span class="bu">echo</span> <span class="st">"scale=2; </span><span class="va">$TOTAL_COST</span><span class="st"> / </span><span class="va">$TOTAL_POSTS</span><span class="st">"</span> <span class="kw">|</span> <span class="fu">bc</span><span class="va">)</span><span class="st">"</span></span>
<span id="cb16-29"><a href="#cb16-29" aria-hidden="true"></a><span class="kw">}</span></span></code></pre>
</div>



<h3 class="wp-block-heading" id="next-steps">Next Steps</h3>



<p>You now have AI-powered content generation capabilities for WordPress.</p>



<h4 class="wp-block-heading" id="recommended-learning-path">Recommended Learning Path</h4>



<p><strong>Week 1</strong>: Basic integration</p>



<ul class="wp-block-list">
<li>Set up Claude/OpenAI APIs</li>



<li>Generate test content</li>



<li>Publish to WordPress</li>
</ul>



<p><strong>Week 2</strong>: Automation</p>



<ul class="wp-block-list">
<li>Build generation scripts</li>



<li>Schedule automated publishing</li>



<li>Implement quality checks</li>
</ul>



<p><strong>Week 3</strong>: Enhancement</p>



<ul class="wp-block-list">
<li>Add SEO optimization</li>



<li>Implement translations</li>



<li>Create content variations</li>
</ul>



<p><strong>Week 4</strong>: Production</p>



<ul class="wp-block-list">
<li>Cost tracking</li>



<li>Quality control systems</li>



<li>Editorial workflows</li>
</ul>



<h4 class="wp-block-heading" id="advanced-topics">Advanced Topics</h4>



<ol class="wp-block-list">
<li><strong><a href="#">Fine-tuning Models</a></strong> &#8211; Custom AI models for your brand</li>



<li><strong><a href="#">Multi-modal Content</a></strong> &#8211; Generate images with text</li>



<li><strong><a href="#">Content Personalization</a></strong> &#8211; AI-driven user targeting</li>
</ol>



<h4 class="wp-block-heading" id="get-more-resources">Get More Resources</h4>



<p><strong><a href="#">Download AI integration scripts</a></strong> including:</p>



<ul class="wp-block-list">
<li>Complete generation system</li>



<li>Quality control tools</li>



<li>Cost tracking utilities</li>
</ul>



<p><strong><a href="/#get-started">Join our email course</a></strong> for:</p>



<ul class="wp-block-list">
<li>Weekly WP-CLI tutorials</li>



<li>AI content strategies</li>



<li>Automation best practices</li>
</ul>



<h3 class="wp-block-heading" id="conclusion">Conclusion</h3>



<p>AI-powered content generation with WP-CLI enables scalable WordPress publishing while maintaining quality through human oversight and ethical practices.</p>



<p>What we covered:</p>



<p>✅ Ethical AI content guidelines <br>✅ Claude and OpenAI API integration <br>✅ Automated content generation workflows <br>✅ Content enhancement and optimization <br>✅ Quality control and review systems <br>✅ Cost tracking and management</p>



<p>Use AI responsibly as a tool to augment human creativity—review all content, ensure accuracy, provide genuine value to readers, and maintain editorial standards.</p>



<p><strong>Ready for more?</strong> Learn <a href="#">content strategy</a> or <a href="#">SEO automation</a>.</p>



<p><strong>Questions about AI content generation for WordPress?</strong> Drop a comment below!</p>



<p><strong>Found this helpful?</strong> Share responsibly with other content creators.</p>
<p>The post <a href="https://wpclimastery.com/blog/automate-wordpress-content-with-ai-apis-and-wp-cli-claude-openai/">Automate WordPress Content with AI APIs and WP-CLI (Claude, OpenAI)</a> appeared first on <a href="https://wpclimastery.com">WP-CLI Mastery</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>WordPress REST API + WP-CLI: Complete Automation Integration Guide</title>
		<link>https://wpclimastery.com/blog/wordpress-rest-api-wp-cli-complete-automation-integration-guide/</link>
		
		<dc:creator><![CDATA[Krasen]]></dc:creator>
		<pubDate>Sat, 20 Dec 2025 09:00:00 +0000</pubDate>
				<category><![CDATA[API Integration Tutorials]]></category>
		<category><![CDATA[curl wordpress api]]></category>
		<category><![CDATA[rest api wpcli]]></category>
		<category><![CDATA[wordpress api automation]]></category>
		<category><![CDATA[wordpress rest api]]></category>
		<category><![CDATA[wp-cli rest api]]></category>
		<guid isPermaLink="false">https://wpclimastery.com/?p=139</guid>

					<description><![CDATA[<p>WordPress REST API lets external applications interact with your site, but testing endpoints manually through browsers or Postman wastes time. Authenticating requests, managing tokens, and debugging API responses becomes tedious...</p>
<p>The post <a href="https://wpclimastery.com/blog/wordpress-rest-api-wp-cli-complete-automation-integration-guide/">WordPress REST API + WP-CLI: Complete Automation Integration Guide</a> appeared first on <a href="https://wpclimastery.com">WP-CLI Mastery</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>WordPress REST API lets external applications interact with your site, but testing endpoints manually through browsers or Postman wastes time. Authenticating requests, managing tokens, and debugging API responses becomes tedious without proper tooling.</p>



<p>WP-CLI combined with curl and REST API gives you complete WordPress automation—create posts from external systems, sync content between sites, integrate with third-party services, and build powerful API-driven workflows from your terminal.</p>



<p>In this guide, you’ll learn to leverage WordPress REST API with WP-CLI for automated content management, headless WordPress setups, and integration workflows used by modern WordPress applications.</p>



<h3 class="wp-block-heading" id="why-combine">Why Combine WordPress REST API with WP-CLI?</h3>



<p><a href="https://developer.wordpress.org/rest-api/">WordPress REST API</a> provides HTTP endpoints for WordPress data, while WP-CLI offers direct database access—together they’re unstoppable.</p>



<h4 class="wp-block-heading" id="wordpress-rest-api-limitations-alone">WordPress REST API Limitations Alone</h4>



<p><strong>Authentication complexity</strong>: Setting up OAuth or application passwords is tedious.</p>



<p><strong>Rate limiting</strong>: API requests can be throttled during bulk operations.</p>



<p><strong>Debugging difficulty</strong>: Hard to see what’s happening inside WordPress during API calls.</p>



<p><strong>No direct database</strong>: Can’t bypass API to directly manipulate data when needed.</p>



<p><strong>Testing challenges</strong>: Need external tools to test endpoints during development.</p>



<h4 class="wp-block-heading" id="combined-wp-cli-rest-api-advantages">Combined WP-CLI + REST API Advantages</h4>



<p><strong>Fast prototyping</strong>: Use WP-CLI to create test data for API development.</p>



<p><strong>Hybrid workflows</strong>: Use API for external integration, WP-CLI for direct operations.</p>



<p><strong>Better debugging</strong>: Check database state with WP-CLI while testing API calls.</p>



<p><strong>Authentication bypass</strong>: Use WP-CLI for admin tasks, API for user-facing features.</p>



<p><strong>Complete automation</strong>: Build complex workflows combining both tools.</p>



<p>According to <a href="https://developer.wordpress.org/">WordPress API usage statistics</a>, REST API adoption has grown 300% since 2020, making API skills essential.</p>



<h3 class="wp-block-heading" id="api-basics">WordPress REST API Basics</h3>



<p>Understand WordPress REST API fundamentals before automation.</p>



<h4 class="wp-block-heading" id="test-api-endpoints-with-curl">Test API Endpoints with curl</h4>



<div class="sourceCode" id="cb1">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true"></a><span class="co"># Get site information</span></span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true"></a><span class="ex">curl</span> https://example.com/wp-json/</span>
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true"></a></span>
<span id="cb1-4"><a href="#cb1-4" aria-hidden="true"></a><span class="co"># List all posts</span></span>
<span id="cb1-5"><a href="#cb1-5" aria-hidden="true"></a><span class="ex">curl</span> https://example.com/wp-json/wp/v2/posts</span>
<span id="cb1-6"><a href="#cb1-6" aria-hidden="true"></a></span>
<span id="cb1-7"><a href="#cb1-7" aria-hidden="true"></a><span class="co"># Get specific post</span></span>
<span id="cb1-8"><a href="#cb1-8" aria-hidden="true"></a><span class="ex">curl</span> https://example.com/wp-json/wp/v2/posts/123</span>
<span id="cb1-9"><a href="#cb1-9" aria-hidden="true"></a></span>
<span id="cb1-10"><a href="#cb1-10" aria-hidden="true"></a><span class="co"># List users</span></span>
<span id="cb1-11"><a href="#cb1-11" aria-hidden="true"></a><span class="ex">curl</span> https://example.com/wp-json/wp/v2/users</span>
<span id="cb1-12"><a href="#cb1-12" aria-hidden="true"></a></span>
<span id="cb1-13"><a href="#cb1-13" aria-hidden="true"></a><span class="co"># Get categories</span></span>
<span id="cb1-14"><a href="#cb1-14" aria-hidden="true"></a><span class="ex">curl</span> https://example.com/wp-json/wp/v2/categories</span></code></pre>
</div>



<h4 class="wp-block-heading" id="pretty-print-json-responses">Pretty Print JSON Responses</h4>



<div class="sourceCode" id="cb2">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true"></a><span class="co"># Install jq for JSON formatting</span></span>
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true"></a><span class="ex">apt-get</span> install jq</span>
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true"></a></span>
<span id="cb2-4"><a href="#cb2-4" aria-hidden="true"></a><span class="co"># Pretty print API response</span></span>
<span id="cb2-5"><a href="#cb2-5" aria-hidden="true"></a><span class="ex">curl</span> -s https://example.com/wp-json/wp/v2/posts <span class="kw">|</span> <span class="ex">jq</span> <span class="st">'.'</span></span>
<span id="cb2-6"><a href="#cb2-6" aria-hidden="true"></a></span>
<span id="cb2-7"><a href="#cb2-7" aria-hidden="true"></a><span class="co"># Extract specific fields</span></span>
<span id="cb2-8"><a href="#cb2-8" aria-hidden="true"></a><span class="ex">curl</span> -s https://example.com/wp-json/wp/v2/posts <span class="kw">|</span> <span class="ex">jq</span> <span class="st">'.[].title.rendered'</span></span>
<span id="cb2-9"><a href="#cb2-9" aria-hidden="true"></a></span>
<span id="cb2-10"><a href="#cb2-10" aria-hidden="true"></a><span class="co"># Get post count</span></span>
<span id="cb2-11"><a href="#cb2-11" aria-hidden="true"></a><span class="ex">curl</span> -s https://example.com/wp-json/wp/v2/posts <span class="kw">|</span> <span class="ex">jq</span> <span class="st">'length'</span></span></code></pre>
</div>



<h4 class="wp-block-heading" id="verify-rest-api-is-enabled">Verify REST API is Enabled</h4>



<div class="sourceCode" id="cb3">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true"></a><span class="co"># Check if REST API responds</span></span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true"></a><span class="ex">curl</span> -I https://example.com/wp-json/</span>
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true"></a></span>
<span id="cb3-4"><a href="#cb3-4" aria-hidden="true"></a><span class="co"># Should return: HTTP/1.1 200 OK</span></span>
<span id="cb3-5"><a href="#cb3-5" aria-hidden="true"></a></span>
<span id="cb3-6"><a href="#cb3-6" aria-hidden="true"></a><span class="co"># Use WP-CLI to check REST API status</span></span>
<span id="cb3-7"><a href="#cb3-7" aria-hidden="true"></a><span class="ex">wp</span> rest</span>
<span id="cb3-8"><a href="#cb3-8" aria-hidden="true"></a></span>
<span id="cb3-9"><a href="#cb3-9" aria-hidden="true"></a><span class="co"># List all available REST routes</span></span>
<span id="cb3-10"><a href="#cb3-10" aria-hidden="true"></a><span class="ex">wp</span> rest route list</span></code></pre>
</div>



<p>Learn more in the <a href="https://developer.wordpress.org/rest-api/reference/">WordPress REST API handbook</a>.</p>



<h3 class="wp-block-heading" id="authentication">REST API Authentication</h3>



<p>Authenticate API requests for write operations.</p>



<h4 class="wp-block-heading" id="application-passwords-recommended">Application Passwords (Recommended)</h4>



<div class="sourceCode" id="cb4">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true"></a><span class="co"># Create application password with WP-CLI</span></span>
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true"></a><span class="ex">wp</span> user application-password create admin <span class="st">"API Automation"</span> --porcelain</span>
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true"></a></span>
<span id="cb4-4"><a href="#cb4-4" aria-hidden="true"></a><span class="co"># Returns: password_hash</span></span>
<span id="cb4-5"><a href="#cb4-5" aria-hidden="true"></a></span>
<span id="cb4-6"><a href="#cb4-6" aria-hidden="true"></a><span class="co"># Use in curl request</span></span>
<span id="cb4-7"><a href="#cb4-7" aria-hidden="true"></a><span class="ex">curl</span> -u admin:password_hash <span class="kw">\</span></span>
<span id="cb4-8"><a href="#cb4-8" aria-hidden="true"></a>    <span class="ex">https</span>://example.com/wp-json/wp/v2/posts</span>
<span id="cb4-9"><a href="#cb4-9" aria-hidden="true"></a></span>
<span id="cb4-10"><a href="#cb4-10" aria-hidden="true"></a><span class="co"># Test authentication</span></span>
<span id="cb4-11"><a href="#cb4-11" aria-hidden="true"></a><span class="ex">curl</span> -u admin:password_hash <span class="kw">\</span></span>
<span id="cb4-12"><a href="#cb4-12" aria-hidden="true"></a>    <span class="ex">https</span>://example.com/wp-json/wp/v2/users/me</span></code></pre>
</div>



<p><strong>Best Practice</strong>: Store credentials in environment variables, never hardcode in scripts.</p>



<div class="sourceCode" id="cb5">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true"></a><span class="co"># Set environment variables</span></span>
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true"></a><span class="bu">export</span> <span class="va">WP_USER=</span><span class="st">"admin"</span></span>
<span id="cb5-3"><a href="#cb5-3" aria-hidden="true"></a><span class="bu">export</span> <span class="va">WP_APP_PASSWORD=</span><span class="st">"xxxx xxxx xxxx xxxx"</span></span>
<span id="cb5-4"><a href="#cb5-4" aria-hidden="true"></a></span>
<span id="cb5-5"><a href="#cb5-5" aria-hidden="true"></a><span class="co"># Use in scripts</span></span>
<span id="cb5-6"><a href="#cb5-6" aria-hidden="true"></a><span class="ex">curl</span> -u <span class="st">"</span><span class="va">$WP_USER</span><span class="st">:</span><span class="va">$WP_APP_PASSWORD</span><span class="st">"</span> <span class="kw">\</span></span>
<span id="cb5-7"><a href="#cb5-7" aria-hidden="true"></a>    <span class="ex">https</span>://example.com/wp-json/wp/v2/posts</span></code></pre>
</div>



<h4 class="wp-block-heading" id="basic-authentication-development-only">Basic Authentication (Development Only)</h4>



<div class="sourceCode" id="cb6">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true"></a><span class="co"># Install Basic Auth plugin (development only!)</span></span>
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true"></a><span class="ex">wp</span> plugin install https://github.com/WP-API/Basic-Auth/archive/master.zip --activate</span>
<span id="cb6-3"><a href="#cb6-3" aria-hidden="true"></a></span>
<span id="cb6-4"><a href="#cb6-4" aria-hidden="true"></a><span class="co"># Use with curl</span></span>
<span id="cb6-5"><a href="#cb6-5" aria-hidden="true"></a><span class="ex">curl</span> -u username:password <span class="kw">\</span></span>
<span id="cb6-6"><a href="#cb6-6" aria-hidden="true"></a>    <span class="ex">https</span>://example.com/wp-json/wp/v2/posts</span>
<span id="cb6-7"><a href="#cb6-7" aria-hidden="true"></a></span>
<span id="cb6-8"><a href="#cb6-8" aria-hidden="true"></a><span class="co"># NEVER use Basic Auth on production (insecure over HTTP)</span></span></code></pre>
</div>



<h3 class="wp-block-heading" id="create-content">Creating Content via REST API</h3>



<p>Automate content creation using API endpoints.</p>



<h4 class="wp-block-heading" id="create-posts-with-curl">Create Posts with curl</h4>



<div class="sourceCode" id="cb7">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true"></a><span class="co"># Create simple post</span></span>
<span id="cb7-2"><a href="#cb7-2" aria-hidden="true"></a><span class="ex">curl</span> -X POST <span class="kw">\</span></span>
<span id="cb7-3"><a href="#cb7-3" aria-hidden="true"></a>    <span class="ex">-u</span> admin:app_password <span class="kw">\</span></span>
<span id="cb7-4"><a href="#cb7-4" aria-hidden="true"></a>    <span class="ex">-H</span> <span class="st">"Content-Type: application/json"</span> <span class="kw">\</span></span>
<span id="cb7-5"><a href="#cb7-5" aria-hidden="true"></a>    <span class="ex">-d</span> <span class="st">'{</span></span>
<span id="cb7-6"><a href="#cb7-6" aria-hidden="true"></a><span class="st">        "title": "New Post via API",</span></span>
<span id="cb7-7"><a href="#cb7-7" aria-hidden="true"></a><span class="st">        "content": "This post was created via REST API",</span></span>
<span id="cb7-8"><a href="#cb7-8" aria-hidden="true"></a><span class="st">        "status": "publish"</span></span>
<span id="cb7-9"><a href="#cb7-9" aria-hidden="true"></a><span class="st">    }'</span> <span class="kw">\</span></span>
<span id="cb7-10"><a href="#cb7-10" aria-hidden="true"></a>    <span class="ex">https</span>://example.com/wp-json/wp/v2/posts</span>
<span id="cb7-11"><a href="#cb7-11" aria-hidden="true"></a></span>
<span id="cb7-12"><a href="#cb7-12" aria-hidden="true"></a><span class="co"># Create post with categories and tags</span></span>
<span id="cb7-13"><a href="#cb7-13" aria-hidden="true"></a><span class="ex">curl</span> -X POST <span class="kw">\</span></span>
<span id="cb7-14"><a href="#cb7-14" aria-hidden="true"></a>    <span class="ex">-u</span> admin:app_password <span class="kw">\</span></span>
<span id="cb7-15"><a href="#cb7-15" aria-hidden="true"></a>    <span class="ex">-H</span> <span class="st">"Content-Type: application/json"</span> <span class="kw">\</span></span>
<span id="cb7-16"><a href="#cb7-16" aria-hidden="true"></a>    <span class="ex">-d</span> <span class="st">'{</span></span>
<span id="cb7-17"><a href="#cb7-17" aria-hidden="true"></a><span class="st">        "title": "Categorized Post",</span></span>
<span id="cb7-18"><a href="#cb7-18" aria-hidden="true"></a><span class="st">        "content": "Post content here",</span></span>
<span id="cb7-19"><a href="#cb7-19" aria-hidden="true"></a><span class="st">        "status": "publish",</span></span>
<span id="cb7-20"><a href="#cb7-20" aria-hidden="true"></a><span class="st">        "categories": [1, 5],</span></span>
<span id="cb7-21"><a href="#cb7-21" aria-hidden="true"></a><span class="st">        "tags": [10, 15, 20]</span></span>
<span id="cb7-22"><a href="#cb7-22" aria-hidden="true"></a><span class="st">    }'</span> <span class="kw">\</span></span>
<span id="cb7-23"><a href="#cb7-23" aria-hidden="true"></a>    <span class="ex">https</span>://example.com/wp-json/wp/v2/posts</span></code></pre>
</div>



<h4 class="wp-block-heading" id="create-posts-from-external-data">Create Posts from External Data</h4>



<div class="sourceCode" id="cb8">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true"></a><span class="co">#!/bin/bash</span></span>
<span id="cb8-2"><a href="#cb8-2" aria-hidden="true"></a><span class="co"># import-from-api.sh - Import content from external API</span></span>
<span id="cb8-3"><a href="#cb8-3" aria-hidden="true"></a></span>
<span id="cb8-4"><a href="#cb8-4" aria-hidden="true"></a><span class="va">EXTERNAL_API=</span><span class="st">"https://api.example.com/articles"</span></span>
<span id="cb8-5"><a href="#cb8-5" aria-hidden="true"></a><span class="va">WP_SITE=</span><span class="st">"https://mysite.com"</span></span>
<span id="cb8-6"><a href="#cb8-6" aria-hidden="true"></a><span class="va">WP_USER=</span><span class="st">"admin"</span></span>
<span id="cb8-7"><a href="#cb8-7" aria-hidden="true"></a><span class="va">WP_PASS=</span><span class="st">"app_password"</span></span>
<span id="cb8-8"><a href="#cb8-8" aria-hidden="true"></a></span>
<span id="cb8-9"><a href="#cb8-9" aria-hidden="true"></a><span class="co"># Fetch external content</span></span>
<span id="cb8-10"><a href="#cb8-10" aria-hidden="true"></a><span class="ex">curl</span> -s <span class="st">"</span><span class="va">$EXTERNAL_API</span><span class="st">"</span> <span class="kw">|</span> <span class="ex">jq</span> -c <span class="st">'.[]'</span> <span class="kw">|</span> <span class="kw">while</span> <span class="bu">read</span> <span class="va">article</span>; <span class="kw">do</span></span>
<span id="cb8-11"><a href="#cb8-11" aria-hidden="true"></a>    <span class="va">TITLE=$(</span><span class="bu">echo</span> <span class="st">"</span><span class="va">$article</span><span class="st">"</span> <span class="kw">|</span> <span class="ex">jq</span> -r <span class="st">'.title'</span><span class="va">)</span></span>
<span id="cb8-12"><a href="#cb8-12" aria-hidden="true"></a>    <span class="va">CONTENT=$(</span><span class="bu">echo</span> <span class="st">"</span><span class="va">$article</span><span class="st">"</span> <span class="kw">|</span> <span class="ex">jq</span> -r <span class="st">'.content'</span><span class="va">)</span></span>
<span id="cb8-13"><a href="#cb8-13" aria-hidden="true"></a></span>
<span id="cb8-14"><a href="#cb8-14" aria-hidden="true"></a>    <span class="bu">echo</span> <span class="st">"Importing: </span><span class="va">$TITLE</span><span class="st">"</span></span>
<span id="cb8-15"><a href="#cb8-15" aria-hidden="true"></a></span>
<span id="cb8-16"><a href="#cb8-16" aria-hidden="true"></a>    <span class="co"># Create WordPress post</span></span>
<span id="cb8-17"><a href="#cb8-17" aria-hidden="true"></a>    <span class="ex">curl</span> -X POST <span class="kw">\</span></span>
<span id="cb8-18"><a href="#cb8-18" aria-hidden="true"></a>        <span class="ex">-u</span> <span class="st">"</span><span class="va">$WP_USER</span><span class="st">:</span><span class="va">$WP_PASS</span><span class="st">"</span> <span class="kw">\</span></span>
<span id="cb8-19"><a href="#cb8-19" aria-hidden="true"></a>        <span class="ex">-H</span> <span class="st">"Content-Type: application/json"</span> <span class="kw">\</span></span>
<span id="cb8-20"><a href="#cb8-20" aria-hidden="true"></a>        <span class="ex">-d</span> <span class="st">"{</span></span>
<span id="cb8-21"><a href="#cb8-21" aria-hidden="true"></a><span class="st">            </span><span class="dt">\"</span><span class="st">title</span><span class="dt">\"</span><span class="st">: </span><span class="dt">\"</span><span class="va">$TITLE</span><span class="dt">\"</span><span class="st">,</span></span>
<span id="cb8-22"><a href="#cb8-22" aria-hidden="true"></a><span class="st">            </span><span class="dt">\"</span><span class="st">content</span><span class="dt">\"</span><span class="st">: </span><span class="dt">\"</span><span class="va">$CONTENT</span><span class="dt">\"</span><span class="st">,</span></span>
<span id="cb8-23"><a href="#cb8-23" aria-hidden="true"></a><span class="st">            </span><span class="dt">\"</span><span class="st">status</span><span class="dt">\"</span><span class="st">: </span><span class="dt">\"</span><span class="st">draft</span><span class="dt">\"</span></span>
<span id="cb8-24"><a href="#cb8-24" aria-hidden="true"></a><span class="st">        }"</span> <span class="kw">\</span></span>
<span id="cb8-25"><a href="#cb8-25" aria-hidden="true"></a>        <span class="st">"</span><span class="va">$WP_SITE</span><span class="st">/wp-json/wp/v2/posts"</span></span>
<span id="cb8-26"><a href="#cb8-26" aria-hidden="true"></a><span class="kw">done</span></span>
<span id="cb8-27"><a href="#cb8-27" aria-hidden="true"></a></span>
<span id="cb8-28"><a href="#cb8-28" aria-hidden="true"></a><span class="bu">echo</span> <span class="st">"✓ Import complete"</span></span></code></pre>
</div>



<p><strong>Use Case</strong>: Sync content from headless CMS, import RSS feeds, or aggregate content from multiple sources.</p>



<h4 class="wp-block-heading" id="update-posts">Update Posts</h4>



<div class="sourceCode" id="cb9">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true"></a><span class="co"># Update post title</span></span>
<span id="cb9-2"><a href="#cb9-2" aria-hidden="true"></a><span class="ex">curl</span> -X POST <span class="kw">\</span></span>
<span id="cb9-3"><a href="#cb9-3" aria-hidden="true"></a>    <span class="ex">-u</span> admin:app_password <span class="kw">\</span></span>
<span id="cb9-4"><a href="#cb9-4" aria-hidden="true"></a>    <span class="ex">-H</span> <span class="st">"Content-Type: application/json"</span> <span class="kw">\</span></span>
<span id="cb9-5"><a href="#cb9-5" aria-hidden="true"></a>    <span class="ex">-d</span> <span class="st">'{"title": "Updated Title"}'</span> <span class="kw">\</span></span>
<span id="cb9-6"><a href="#cb9-6" aria-hidden="true"></a>    <span class="ex">https</span>://example.com/wp-json/wp/v2/posts/123</span>
<span id="cb9-7"><a href="#cb9-7" aria-hidden="true"></a></span>
<span id="cb9-8"><a href="#cb9-8" aria-hidden="true"></a><span class="co"># Update post content</span></span>
<span id="cb9-9"><a href="#cb9-9" aria-hidden="true"></a><span class="ex">curl</span> -X POST <span class="kw">\</span></span>
<span id="cb9-10"><a href="#cb9-10" aria-hidden="true"></a>    <span class="ex">-u</span> admin:app_password <span class="kw">\</span></span>
<span id="cb9-11"><a href="#cb9-11" aria-hidden="true"></a>    <span class="ex">-H</span> <span class="st">"Content-Type: application/json"</span> <span class="kw">\</span></span>
<span id="cb9-12"><a href="#cb9-12" aria-hidden="true"></a>    <span class="ex">-d</span> <span class="st">'{"content": "New content here"}'</span> <span class="kw">\</span></span>
<span id="cb9-13"><a href="#cb9-13" aria-hidden="true"></a>    <span class="ex">https</span>://example.com/wp-json/wp/v2/posts/123</span>
<span id="cb9-14"><a href="#cb9-14" aria-hidden="true"></a></span>
<span id="cb9-15"><a href="#cb9-15" aria-hidden="true"></a><span class="co"># Change post status</span></span>
<span id="cb9-16"><a href="#cb9-16" aria-hidden="true"></a><span class="ex">curl</span> -X POST <span class="kw">\</span></span>
<span id="cb9-17"><a href="#cb9-17" aria-hidden="true"></a>    <span class="ex">-u</span> admin:app_password <span class="kw">\</span></span>
<span id="cb9-18"><a href="#cb9-18" aria-hidden="true"></a>    <span class="ex">-H</span> <span class="st">"Content-Type: application/json"</span> <span class="kw">\</span></span>
<span id="cb9-19"><a href="#cb9-19" aria-hidden="true"></a>    <span class="ex">-d</span> <span class="st">'{"status": "publish"}'</span> <span class="kw">\</span></span>
<span id="cb9-20"><a href="#cb9-20" aria-hidden="true"></a>    <span class="ex">https</span>://example.com/wp-json/wp/v2/posts/123</span></code></pre>
</div>



<h3 class="wp-block-heading" id="wpcli-rest">WP-CLI REST Commands</h3>



<p>Use WP-CLI’s built-in REST functionality for testing.</p>



<h4 class="wp-block-heading" id="list-rest-routes">List REST Routes</h4>



<div class="sourceCode" id="cb10">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true"></a><span class="co"># Show all REST routes</span></span>
<span id="cb10-2"><a href="#cb10-2" aria-hidden="true"></a><span class="ex">wp</span> rest route list</span>
<span id="cb10-3"><a href="#cb10-3" aria-hidden="true"></a></span>
<span id="cb10-4"><a href="#cb10-4" aria-hidden="true"></a><span class="co"># Show specific namespace</span></span>
<span id="cb10-5"><a href="#cb10-5" aria-hidden="true"></a><span class="ex">wp</span> rest route list --namespace=wp/v2</span>
<span id="cb10-6"><a href="#cb10-6" aria-hidden="true"></a></span>
<span id="cb10-7"><a href="#cb10-7" aria-hidden="true"></a><span class="co"># Filter routes</span></span>
<span id="cb10-8"><a href="#cb10-8" aria-hidden="true"></a><span class="ex">wp</span> rest route list <span class="kw">|</span> <span class="fu">grep</span> posts</span></code></pre>
</div>



<h4 class="wp-block-heading" id="execute-rest-requests-with-wp-cli">Execute REST Requests with WP-CLI</h4>



<div class="sourceCode" id="cb11">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true"></a><span class="co"># GET request</span></span>
<span id="cb11-2"><a href="#cb11-2" aria-hidden="true"></a><span class="ex">wp</span> rest get /wp/v2/posts</span>
<span id="cb11-3"><a href="#cb11-3" aria-hidden="true"></a></span>
<span id="cb11-4"><a href="#cb11-4" aria-hidden="true"></a><span class="co"># GET specific post</span></span>
<span id="cb11-5"><a href="#cb11-5" aria-hidden="true"></a><span class="ex">wp</span> rest get /wp/v2/posts/123</span>
<span id="cb11-6"><a href="#cb11-6" aria-hidden="true"></a></span>
<span id="cb11-7"><a href="#cb11-7" aria-hidden="true"></a><span class="co"># POST request (create content)</span></span>
<span id="cb11-8"><a href="#cb11-8" aria-hidden="true"></a><span class="ex">wp</span> rest post /wp/v2/posts <span class="kw">\</span></span>
<span id="cb11-9"><a href="#cb11-9" aria-hidden="true"></a>    <span class="ex">--title</span>=<span class="st">"New Post"</span> <span class="kw">\</span></span>
<span id="cb11-10"><a href="#cb11-10" aria-hidden="true"></a>    <span class="ex">--content</span>=<span class="st">"Post content"</span> <span class="kw">\</span></span>
<span id="cb11-11"><a href="#cb11-11" aria-hidden="true"></a>    <span class="ex">--status</span>=publish</span>
<span id="cb11-12"><a href="#cb11-12" aria-hidden="true"></a></span>
<span id="cb11-13"><a href="#cb11-13" aria-hidden="true"></a><span class="co"># DELETE request</span></span>
<span id="cb11-14"><a href="#cb11-14" aria-hidden="true"></a><span class="ex">wp</span> rest delete /wp/v2/posts/123 --force=true</span></code></pre>
</div>



<p><strong>Advantage</strong>: WP-CLI REST commands bypass authentication—perfect for local development and testing.</p>



<h3 class="wp-block-heading" id="hybrid-workflows">Hybrid WP-CLI + REST API Workflows</h3>



<p>Combine WP-CLI and REST API for powerful automation.</p>



<h4 class="wp-block-heading" id="content-sync-between-sites">Content Sync Between Sites</h4>



<div class="sourceCode" id="cb12">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true"></a><span class="co">#!/bin/bash</span></span>
<span id="cb12-2"><a href="#cb12-2" aria-hidden="true"></a><span class="co"># sync-content-between-sites.sh</span></span>
<span id="cb12-3"><a href="#cb12-3" aria-hidden="true"></a></span>
<span id="cb12-4"><a href="#cb12-4" aria-hidden="true"></a><span class="va">SOURCE_SITE=</span><span class="st">"https://source.com"</span></span>
<span id="cb12-5"><a href="#cb12-5" aria-hidden="true"></a><span class="va">TARGET_SITE=</span><span class="st">"/var/www/target-site"</span></span>
<span id="cb12-6"><a href="#cb12-6" aria-hidden="true"></a><span class="va">WP_USER=</span><span class="st">"admin"</span></span>
<span id="cb12-7"><a href="#cb12-7" aria-hidden="true"></a><span class="va">WP_PASS=</span><span class="st">"app_password"</span></span>
<span id="cb12-8"><a href="#cb12-8" aria-hidden="true"></a></span>
<span id="cb12-9"><a href="#cb12-9" aria-hidden="true"></a><span class="co"># Export posts from source via API</span></span>
<span id="cb12-10"><a href="#cb12-10" aria-hidden="true"></a><span class="ex">curl</span> -s <span class="st">"</span><span class="va">$SOURCE_SITE</span><span class="st">/wp-json/wp/v2/posts?per_page=100"</span> <span class="op">&gt;</span> /tmp/posts.json</span>
<span id="cb12-11"><a href="#cb12-11" aria-hidden="true"></a></span>
<span id="cb12-12"><a href="#cb12-12" aria-hidden="true"></a><span class="co"># Import to target with WP-CLI</span></span>
<span id="cb12-13"><a href="#cb12-13" aria-hidden="true"></a><span class="bu">cd</span> <span class="st">"</span><span class="va">$TARGET_SITE</span><span class="st">"</span></span>
<span id="cb12-14"><a href="#cb12-14" aria-hidden="true"></a></span>
<span id="cb12-15"><a href="#cb12-15" aria-hidden="true"></a><span class="fu">cat</span> /tmp/posts.json <span class="kw">|</span> <span class="ex">jq</span> -c <span class="st">'.[]'</span> <span class="kw">|</span> <span class="kw">while</span> <span class="bu">read</span> <span class="va">post</span>; <span class="kw">do</span></span>
<span id="cb12-16"><a href="#cb12-16" aria-hidden="true"></a>    <span class="va">TITLE=$(</span><span class="bu">echo</span> <span class="st">"</span><span class="va">$post</span><span class="st">"</span> <span class="kw">|</span> <span class="ex">jq</span> -r <span class="st">'.title.rendered'</span><span class="va">)</span></span>
<span id="cb12-17"><a href="#cb12-17" aria-hidden="true"></a>    <span class="va">CONTENT=$(</span><span class="bu">echo</span> <span class="st">"</span><span class="va">$post</span><span class="st">"</span> <span class="kw">|</span> <span class="ex">jq</span> -r <span class="st">'.content.rendered'</span><span class="va">)</span></span>
<span id="cb12-18"><a href="#cb12-18" aria-hidden="true"></a></span>
<span id="cb12-19"><a href="#cb12-19" aria-hidden="true"></a>    <span class="bu">echo</span> <span class="st">"Importing: </span><span class="va">$TITLE</span><span class="st">"</span></span>
<span id="cb12-20"><a href="#cb12-20" aria-hidden="true"></a></span>
<span id="cb12-21"><a href="#cb12-21" aria-hidden="true"></a>    <span class="co"># Use WP-CLI for faster import</span></span>
<span id="cb12-22"><a href="#cb12-22" aria-hidden="true"></a>    <span class="ex">wp</span> post create <span class="kw">\</span></span>
<span id="cb12-23"><a href="#cb12-23" aria-hidden="true"></a>        <span class="ex">--post_title</span>=<span class="st">"</span><span class="va">$TITLE</span><span class="st">"</span> <span class="kw">\</span></span>
<span id="cb12-24"><a href="#cb12-24" aria-hidden="true"></a>        <span class="ex">--post_content</span>=<span class="st">"</span><span class="va">$CONTENT</span><span class="st">"</span> <span class="kw">\</span></span>
<span id="cb12-25"><a href="#cb12-25" aria-hidden="true"></a>        <span class="ex">--post_status</span>=publish</span>
<span id="cb12-26"><a href="#cb12-26" aria-hidden="true"></a><span class="kw">done</span></span>
<span id="cb12-27"><a href="#cb12-27" aria-hidden="true"></a></span>
<span id="cb12-28"><a href="#cb12-28" aria-hidden="true"></a><span class="fu">rm</span> /tmp/posts.json</span>
<span id="cb12-29"><a href="#cb12-29" aria-hidden="true"></a><span class="bu">echo</span> <span class="st">"✓ Content sync complete"</span></span></code></pre>
</div>



<h4 class="wp-block-heading" id="headless-wordpress-content-publishing">Headless WordPress Content Publishing</h4>



<div class="sourceCode" id="cb13">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true"></a><span class="co">#!/bin/bash</span></span>
<span id="cb13-2"><a href="#cb13-2" aria-hidden="true"></a><span class="co"># headless-publish.sh - Publish to headless WordPress</span></span>
<span id="cb13-3"><a href="#cb13-3" aria-hidden="true"></a></span>
<span id="cb13-4"><a href="#cb13-4" aria-hidden="true"></a><span class="va">WP_API=</span><span class="st">"https://headless-wp.com/wp-json/wp/v2"</span></span>
<span id="cb13-5"><a href="#cb13-5" aria-hidden="true"></a><span class="va">WP_USER=</span><span class="st">"admin"</span></span>
<span id="cb13-6"><a href="#cb13-6" aria-hidden="true"></a><span class="va">WP_PASS=</span><span class="st">"app_password"</span></span>
<span id="cb13-7"><a href="#cb13-7" aria-hidden="true"></a></span>
<span id="cb13-8"><a href="#cb13-8" aria-hidden="true"></a><span class="co"># Create content locally with WP-CLI</span></span>
<span id="cb13-9"><a href="#cb13-9" aria-hidden="true"></a><span class="ex">wp</span> post create <span class="kw">\</span></span>
<span id="cb13-10"><a href="#cb13-10" aria-hidden="true"></a>    <span class="ex">--post_title</span>=<span class="st">"Headless Post"</span> <span class="kw">\</span></span>
<span id="cb13-11"><a href="#cb13-11" aria-hidden="true"></a>    <span class="ex">--post_content</span>=<span class="st">"Content here"</span> <span class="kw">\</span></span>
<span id="cb13-12"><a href="#cb13-12" aria-hidden="true"></a>    <span class="ex">--post_status</span>=draft <span class="kw">\</span></span>
<span id="cb13-13"><a href="#cb13-13" aria-hidden="true"></a>    <span class="ex">--porcelain</span> <span class="op">&gt;</span> /tmp/post_id.txt</span>
<span id="cb13-14"><a href="#cb13-14" aria-hidden="true"></a></span>
<span id="cb13-15"><a href="#cb13-15" aria-hidden="true"></a><span class="va">POST_ID=$(</span><span class="fu">cat</span> /tmp/post_id.txt<span class="va">)</span></span>
<span id="cb13-16"><a href="#cb13-16" aria-hidden="true"></a></span>
<span id="cb13-17"><a href="#cb13-17" aria-hidden="true"></a><span class="co"># Export post data</span></span>
<span id="cb13-18"><a href="#cb13-18" aria-hidden="true"></a><span class="va">POST_DATA=$(</span><span class="ex">wp</span> post get <span class="va">$POST_ID</span> --format=json<span class="va">)</span></span>
<span id="cb13-19"><a href="#cb13-19" aria-hidden="true"></a></span>
<span id="cb13-20"><a href="#cb13-20" aria-hidden="true"></a><span class="co"># Publish via REST API to headless instance</span></span>
<span id="cb13-21"><a href="#cb13-21" aria-hidden="true"></a><span class="ex">curl</span> -X POST <span class="kw">\</span></span>
<span id="cb13-22"><a href="#cb13-22" aria-hidden="true"></a>    <span class="ex">-u</span> <span class="st">"</span><span class="va">$WP_USER</span><span class="st">:</span><span class="va">$WP_PASS</span><span class="st">"</span> <span class="kw">\</span></span>
<span id="cb13-23"><a href="#cb13-23" aria-hidden="true"></a>    <span class="ex">-H</span> <span class="st">"Content-Type: application/json"</span> <span class="kw">\</span></span>
<span id="cb13-24"><a href="#cb13-24" aria-hidden="true"></a>    <span class="ex">-d</span> <span class="st">"</span><span class="va">$POST_DATA</span><span class="st">"</span> <span class="kw">\</span></span>
<span id="cb13-25"><a href="#cb13-25" aria-hidden="true"></a>    <span class="st">"</span><span class="va">$WP_API</span><span class="st">/posts"</span></span>
<span id="cb13-26"><a href="#cb13-26" aria-hidden="true"></a></span>
<span id="cb13-27"><a href="#cb13-27" aria-hidden="true"></a><span class="bu">echo</span> <span class="st">"✓ Published to headless WordPress"</span></span></code></pre>
</div>



<h4 class="wp-block-heading" id="automated-content-moderation">Automated Content Moderation</h4>



<div class="sourceCode" id="cb14">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true"></a><span class="co">#!/bin/bash</span></span>
<span id="cb14-2"><a href="#cb14-2" aria-hidden="true"></a><span class="co"># moderate-content.sh - Auto-moderate spam content</span></span>
<span id="cb14-3"><a href="#cb14-3" aria-hidden="true"></a></span>
<span id="cb14-4"><a href="#cb14-4" aria-hidden="true"></a><span class="va">WP_SITE=</span><span class="st">"/var/www/html"</span></span>
<span id="cb14-5"><a href="#cb14-5" aria-hidden="true"></a><span class="va">API_URL=</span><span class="st">"https://example.com/wp-json/wp/v2"</span></span>
<span id="cb14-6"><a href="#cb14-6" aria-hidden="true"></a><span class="va">WP_USER=</span><span class="st">"admin"</span></span>
<span id="cb14-7"><a href="#cb14-7" aria-hidden="true"></a><span class="va">WP_PASS=</span><span class="st">"app_password"</span></span>
<span id="cb14-8"><a href="#cb14-8" aria-hidden="true"></a></span>
<span id="cb14-9"><a href="#cb14-9" aria-hidden="true"></a><span class="bu">cd</span> <span class="st">"</span><span class="va">$WP_SITE</span><span class="st">"</span></span>
<span id="cb14-10"><a href="#cb14-10" aria-hidden="true"></a></span>
<span id="cb14-11"><a href="#cb14-11" aria-hidden="true"></a><span class="co"># Find posts with spam keywords using WP-CLI</span></span>
<span id="cb14-12"><a href="#cb14-12" aria-hidden="true"></a><span class="va">SPAM_POSTS=$(</span><span class="ex">wp</span> post list <span class="kw">\</span></span>
<span id="cb14-13"><a href="#cb14-13" aria-hidden="true"></a>    <span class="ex">--s</span>=<span class="st">"viagra"</span> <span class="kw">\</span></span>
<span id="cb14-14"><a href="#cb14-14" aria-hidden="true"></a>    <span class="ex">--post_status</span>=publish <span class="kw">\</span></span>
<span id="cb14-15"><a href="#cb14-15" aria-hidden="true"></a>    <span class="ex">--format</span>=ids<span class="va">)</span></span>
<span id="cb14-16"><a href="#cb14-16" aria-hidden="true"></a></span>
<span id="cb14-17"><a href="#cb14-17" aria-hidden="true"></a><span class="kw">for</span> <span class="ex">POST_ID</span> in <span class="va">$SPAM_POSTS</span><span class="kw">;</span> <span class="kw">do</span></span>
<span id="cb14-18"><a href="#cb14-18" aria-hidden="true"></a>    <span class="bu">echo</span> <span class="st">"Trashing spam post: </span><span class="va">$POST_ID</span><span class="st">"</span></span>
<span id="cb14-19"><a href="#cb14-19" aria-hidden="true"></a></span>
<span id="cb14-20"><a href="#cb14-20" aria-hidden="true"></a>    <span class="co"># Move to trash via REST API</span></span>
<span id="cb14-21"><a href="#cb14-21" aria-hidden="true"></a>    <span class="ex">curl</span> -X DELETE <span class="kw">\</span></span>
<span id="cb14-22"><a href="#cb14-22" aria-hidden="true"></a>        <span class="ex">-u</span> <span class="st">"</span><span class="va">$WP_USER</span><span class="st">:</span><span class="va">$WP_PASS</span><span class="st">"</span> <span class="kw">\</span></span>
<span id="cb14-23"><a href="#cb14-23" aria-hidden="true"></a>        <span class="st">"</span><span class="va">$API_URL</span><span class="st">/posts/</span><span class="va">$POST_ID</span><span class="st">"</span></span>
<span id="cb14-24"><a href="#cb14-24" aria-hidden="true"></a><span class="kw">done</span></span>
<span id="cb14-25"><a href="#cb14-25" aria-hidden="true"></a></span>
<span id="cb14-26"><a href="#cb14-26" aria-hidden="true"></a><span class="bu">echo</span> <span class="st">"✓ Spam moderation complete"</span></span></code></pre>
</div>



<h3 class="wp-block-heading" id="api-testing">API Testing and Development</h3>



<p>Test custom REST API endpoints during development.</p>



<h4 class="wp-block-heading" id="register-custom-endpoint">Register Custom Endpoint</h4>



<div class="sourceCode" id="cb15">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true"></a><span class="co">// In theme functions.php or plugin</span></span>
<span id="cb15-2"><a href="#cb15-2" aria-hidden="true"></a>add_action<span class="ot">(</span><span class="st">'rest_api_init'</span><span class="ot">,</span> <span class="kw">function</span> <span class="ot">()</span> {</span>
<span id="cb15-3"><a href="#cb15-3" aria-hidden="true"></a>    register_rest_route<span class="ot">(</span><span class="st">'custom/v1'</span><span class="ot">,</span> <span class="st">'/data'</span><span class="ot">,</span> <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb15-4"><a href="#cb15-4" aria-hidden="true"></a>        <span class="st">'methods'</span> =&gt; <span class="st">'GET'</span><span class="ot">,</span></span>
<span id="cb15-5"><a href="#cb15-5" aria-hidden="true"></a>        <span class="st">'callback'</span> =&gt; <span class="st">'custom_api_callback'</span><span class="ot">,</span></span>
<span id="cb15-6"><a href="#cb15-6" aria-hidden="true"></a>        <span class="st">'permission_callback'</span> =&gt; <span class="st">'__return_true'</span></span>
<span id="cb15-7"><a href="#cb15-7" aria-hidden="true"></a>    <span class="ot">));</span></span>
<span id="cb15-8"><a href="#cb15-8" aria-hidden="true"></a>}<span class="ot">);</span></span>
<span id="cb15-9"><a href="#cb15-9" aria-hidden="true"></a></span>
<span id="cb15-10"><a href="#cb15-10" aria-hidden="true"></a><span class="kw">function</span> custom_api_callback<span class="ot">()</span> {</span>
<span id="cb15-11"><a href="#cb15-11" aria-hidden="true"></a>    <span class="kw">return</span> <span class="kw">array</span><span class="ot">(</span><span class="st">'status'</span> =&gt; <span class="st">'success'</span><span class="ot">,</span> <span class="st">'data'</span> =&gt; <span class="st">'Custom API response'</span><span class="ot">);</span></span>
<span id="cb15-12"><a href="#cb15-12" aria-hidden="true"></a>}</span></code></pre>
</div>



<h4 class="wp-block-heading" id="test-custom-endpoint">Test Custom Endpoint</h4>



<div class="sourceCode" id="cb16">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb16-1"><a href="#cb16-1" aria-hidden="true"></a><span class="co"># Test with curl</span></span>
<span id="cb16-2"><a href="#cb16-2" aria-hidden="true"></a><span class="ex">curl</span> https://example.com/wp-json/custom/v1/data</span>
<span id="cb16-3"><a href="#cb16-3" aria-hidden="true"></a></span>
<span id="cb16-4"><a href="#cb16-4" aria-hidden="true"></a><span class="co"># Test with WP-CLI</span></span>
<span id="cb16-5"><a href="#cb16-5" aria-hidden="true"></a><span class="ex">wp</span> rest get /custom/v1/data</span>
<span id="cb16-6"><a href="#cb16-6" aria-hidden="true"></a></span>
<span id="cb16-7"><a href="#cb16-7" aria-hidden="true"></a><span class="co"># Validate response</span></span>
<span id="cb16-8"><a href="#cb16-8" aria-hidden="true"></a><span class="ex">wp</span> rest get /custom/v1/data <span class="kw">|</span> <span class="ex">jq</span> <span class="st">'.status'</span></span></code></pre>
</div>



<h4 class="wp-block-heading" id="automated-api-testing-script">Automated API Testing Script</h4>



<div class="sourceCode" id="cb17">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb17-1"><a href="#cb17-1" aria-hidden="true"></a><span class="co">#!/bin/bash</span></span>
<span id="cb17-2"><a href="#cb17-2" aria-hidden="true"></a><span class="co"># test-api-endpoints.sh</span></span>
<span id="cb17-3"><a href="#cb17-3" aria-hidden="true"></a></span>
<span id="cb17-4"><a href="#cb17-4" aria-hidden="true"></a><span class="va">API_BASE=</span><span class="st">"https://example.com/wp-json/wp/v2"</span></span>
<span id="cb17-5"><a href="#cb17-5" aria-hidden="true"></a></span>
<span id="cb17-6"><a href="#cb17-6" aria-hidden="true"></a><span class="bu">echo</span> <span class="st">"Testing WordPress REST API endpoints..."</span></span>
<span id="cb17-7"><a href="#cb17-7" aria-hidden="true"></a></span>
<span id="cb17-8"><a href="#cb17-8" aria-hidden="true"></a><span class="co"># Test posts endpoint</span></span>
<span id="cb17-9"><a href="#cb17-9" aria-hidden="true"></a><span class="va">HTTP_CODE=$(</span><span class="ex">curl</span> -s -o /dev/null -w <span class="st">"%{http_code}"</span> <span class="st">"</span><span class="va">$API_BASE</span><span class="st">/posts"</span><span class="va">)</span></span>
<span id="cb17-10"><a href="#cb17-10" aria-hidden="true"></a><span class="kw">if</span><span class="bu"> [</span> <span class="st">"</span><span class="va">$HTTP_CODE</span><span class="st">"</span> <span class="ot">-eq</span> 200<span class="bu"> ]</span>; <span class="kw">then</span></span>
<span id="cb17-11"><a href="#cb17-11" aria-hidden="true"></a>    <span class="bu">echo</span> <span class="st">"✓ Posts endpoint: OK"</span></span>
<span id="cb17-12"><a href="#cb17-12" aria-hidden="true"></a><span class="kw">else</span></span>
<span id="cb17-13"><a href="#cb17-13" aria-hidden="true"></a>    <span class="bu">echo</span> <span class="st">"✗ Posts endpoint: FAILED (</span><span class="va">$HTTP_CODE</span><span class="st">)"</span></span>
<span id="cb17-14"><a href="#cb17-14" aria-hidden="true"></a><span class="kw">fi</span></span>
<span id="cb17-15"><a href="#cb17-15" aria-hidden="true"></a></span>
<span id="cb17-16"><a href="#cb17-16" aria-hidden="true"></a><span class="co"># Test users endpoint</span></span>
<span id="cb17-17"><a href="#cb17-17" aria-hidden="true"></a><span class="va">HTTP_CODE=$(</span><span class="ex">curl</span> -s -o /dev/null -w <span class="st">"%{http_code}"</span> <span class="st">"</span><span class="va">$API_BASE</span><span class="st">/users"</span><span class="va">)</span></span>
<span id="cb17-18"><a href="#cb17-18" aria-hidden="true"></a><span class="kw">if</span><span class="bu"> [</span> <span class="st">"</span><span class="va">$HTTP_CODE</span><span class="st">"</span> <span class="ot">-eq</span> 200<span class="bu"> ]</span>; <span class="kw">then</span></span>
<span id="cb17-19"><a href="#cb17-19" aria-hidden="true"></a>    <span class="bu">echo</span> <span class="st">"✓ Users endpoint: OK"</span></span>
<span id="cb17-20"><a href="#cb17-20" aria-hidden="true"></a><span class="kw">else</span></span>
<span id="cb17-21"><a href="#cb17-21" aria-hidden="true"></a>    <span class="bu">echo</span> <span class="st">"✗ Users endpoint: FAILED (</span><span class="va">$HTTP_CODE</span><span class="st">)"</span></span>
<span id="cb17-22"><a href="#cb17-22" aria-hidden="true"></a><span class="kw">fi</span></span>
<span id="cb17-23"><a href="#cb17-23" aria-hidden="true"></a></span>
<span id="cb17-24"><a href="#cb17-24" aria-hidden="true"></a><span class="co"># Test categories endpoint</span></span>
<span id="cb17-25"><a href="#cb17-25" aria-hidden="true"></a><span class="va">HTTP_CODE=$(</span><span class="ex">curl</span> -s -o /dev/null -w <span class="st">"%{http_code}"</span> <span class="st">"</span><span class="va">$API_BASE</span><span class="st">/categories"</span><span class="va">)</span></span>
<span id="cb17-26"><a href="#cb17-26" aria-hidden="true"></a><span class="kw">if</span><span class="bu"> [</span> <span class="st">"</span><span class="va">$HTTP_CODE</span><span class="st">"</span> <span class="ot">-eq</span> 200<span class="bu"> ]</span>; <span class="kw">then</span></span>
<span id="cb17-27"><a href="#cb17-27" aria-hidden="true"></a>    <span class="bu">echo</span> <span class="st">"✓ Categories endpoint: OK"</span></span>
<span id="cb17-28"><a href="#cb17-28" aria-hidden="true"></a><span class="kw">else</span></span>
<span id="cb17-29"><a href="#cb17-29" aria-hidden="true"></a>    <span class="bu">echo</span> <span class="st">"✗ Categories endpoint: FAILED (</span><span class="va">$HTTP_CODE</span><span class="st">)"</span></span>
<span id="cb17-30"><a href="#cb17-30" aria-hidden="true"></a><span class="kw">fi</span></span>
<span id="cb17-31"><a href="#cb17-31" aria-hidden="true"></a></span>
<span id="cb17-32"><a href="#cb17-32" aria-hidden="true"></a><span class="bu">echo</span> <span class="st">"API testing complete"</span></span></code></pre>
</div>



<p>Learn about <a href="https://developer.wordpress.org/rest-api/using-the-rest-api/authentication/">REST API best practices</a> for production.</p>



<h3 class="wp-block-heading" id="next-steps">Next Steps</h3>



<p>You now have WordPress REST API and WP-CLI integration skills for powerful automation workflows.</p>



<h4 class="wp-block-heading" id="recommended-learning-path">Recommended Learning Path</h4>



<p><strong>Week 1</strong>: API fundamentals</p>



<ul class="wp-block-list">
<li>Test endpoints with curl</li>



<li>Set up authentication</li>



<li>Create/update content via API</li>
</ul>



<p><strong>Week 2</strong>: WP-CLI REST commands</p>



<ul class="wp-block-list">
<li>Use <code>wp rest</code> commands</li>



<li>Build hybrid workflows</li>



<li>Test custom endpoints</li>
</ul>



<p><strong>Week 3</strong>: Advanced integration</p>



<ul class="wp-block-list">
<li>Content synchronization</li>



<li>Headless WordPress setup</li>



<li>API-driven automation</li>
</ul>



<p><strong>Week 4</strong>: Production deployment</p>



<ul class="wp-block-list">
<li>Build content pipelines</li>



<li>Implement error handling</li>



<li>Create monitoring systems</li>
</ul>



<h4 class="wp-block-heading" id="advanced-topics">Advanced Topics</h4>



<ol class="wp-block-list">
<li><strong><a href="#">Headless WordPress Architecture</a></strong> &#8211; Complete decoupled setup</li>



<li><strong><a href="#">Custom REST API Endpoints</a></strong> &#8211; Build custom APIs</li>



<li><strong><a href="#">GraphQL + WP-CLI</a></strong> &#8211; Alternative API approach</li>
</ol>



<h4 class="wp-block-heading" id="get-more-resources">Get More Resources</h4>



<p><strong><a href="#">Download API automation scripts</a></strong> including:</p>



<ul class="wp-block-list">
<li>Content sync workflows</li>



<li>API testing suite</li>



<li>Authentication helpers</li>
</ul>



<p><strong><a href="/#get-started">Join our email course</a></strong> for:</p>



<ul class="wp-block-list">
<li>Weekly WP-CLI tutorials</li>



<li>API integration patterns</li>



<li>Modern WordPress architecture</li>
</ul>



<h3 class="wp-block-heading" id="conclusion">Conclusion</h3>



<p>WordPress REST API combined with WP-CLI creates a powerful automation ecosystem for modern WordPress development, from headless setups to complex content workflows.</p>



<p>What we covered:</p>



<p>✅ WordPress REST API basics and authentication <br>✅ Creating and updating content via API <br>✅ WP-CLI REST commands for testing <br>✅ Hybrid WP-CLI + REST API workflows <br>✅ Content sync and automation patterns <br>✅ API testing and development workflows</p>



<p>Master these techniques, and you’ll build sophisticated WordPress automation that integrates with any external system or service.</p>



<p><strong>Ready for more?</strong> Learn <a href="#">WordPress GraphQL integration</a> or <a href="#">headless WordPress architecture</a>.</p>



<p><strong>Questions about WordPress REST API and WP-CLI?</strong> Drop a comment below!</p>



<p><strong>Found this helpful?</strong> Share with other WordPress developers.</p>
<p>The post <a href="https://wpclimastery.com/blog/wordpress-rest-api-wp-cli-complete-automation-integration-guide/">WordPress REST API + WP-CLI: Complete Automation Integration Guide</a> appeared first on <a href="https://wpclimastery.com">WP-CLI Mastery</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Integrate Unsplash API with WordPress Using WP-CLI and Bash</title>
		<link>https://wpclimastery.com/blog/integrate-unsplash-api-with-wordpress-using-wp-cli-and-bash/</link>
		
		<dc:creator><![CDATA[Krasen]]></dc:creator>
		<pubDate>Sun, 30 Nov 2025 09:00:00 +0000</pubDate>
				<category><![CDATA[API Integration Tutorials]]></category>
		<category><![CDATA[featured image automation]]></category>
		<category><![CDATA[unsplash api wordpress]]></category>
		<category><![CDATA[unsplash wordpress automation]]></category>
		<category><![CDATA[wordpress media api]]></category>
		<category><![CDATA[wp-cli api integration]]></category>
		<guid isPermaLink="false">https://wpclimastery.com/?p=14</guid>

					<description><![CDATA[<p>Finding high-quality, royalty-free images for every blog post is time-consuming. Manually searching Unsplash, downloading images, uploading to WordPress, and adding attribution takes 5-10 minutes per post. For content-heavy sites publishing...</p>
<p>The post <a href="https://wpclimastery.com/blog/integrate-unsplash-api-with-wordpress-using-wp-cli-and-bash/">Integrate Unsplash API with WordPress Using WP-CLI and Bash</a> appeared first on <a href="https://wpclimastery.com">WP-CLI Mastery</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Finding high-quality, royalty-free images for every blog post is time-consuming. Manually searching Unsplash, downloading images, uploading to WordPress, and adding attribution takes 5-10 minutes per post. For content-heavy sites publishing daily, that&#8217;s hours of wasted effort every week.</p>



<p>What if you could automatically fetch relevant images from Unsplash and set them as featured images—all from the command line?</p>



<p>In this tutorial, you&#8217;ll learn to integrate the Unsplash API with WordPress using WP-CLI and Bash. You&#8217;ll build a complete automation system that searches for images, downloads them, imports to WordPress media library, sets featured images, and handles proper attribution automatically.</p>



<p>This is a key component of the automated blog publishing pipeline you&#8217;ll build in WPCLI Mastery.</p>



<h3 class="wp-block-heading" id="why-automate-images-with-unsplash-why-unsplash">Why Automate Images with Unsplash?</h3>



<h4 class="wp-block-heading" id="the-manual-image-problem">The Manual Image Problem</h4>



<p><strong>Typical workflow:</strong></p>



<ol class="wp-block-list">
<li>Search Unsplash for relevant image (2 min)</li>



<li>Download image (30 sec)</li>



<li>Upload to WordPress (1 min)</li>



<li>Set as featured image (30 sec)</li>



<li>Add attribution in caption/alt text (1 min)</li>
</ol>



<p><strong>Total: ~5 minutes per post</strong></p>



<p>For 20 posts/month =&nbsp;<strong>100 minutes wasted</strong></p>



<h4 class="wp-block-heading" id="automated-solution">Automated Solution</h4>



<p>With WP-CLI + Unsplash API:</p>



<pre class="wp-block-code"><code><em># One command, 5 seconds</em>
wp unsplash set-featured 123 --query="technology"
</code></pre>



<p><strong>Result:</strong></p>



<ul class="wp-block-list">
<li>Image downloaded</li>



<li>Imported to media library</li>



<li>Set as featured image</li>



<li>Attribution added</li>



<li>Alt text optimized</li>
</ul>



<h4 class="wp-block-heading" id="unsplash-benefits">Unsplash Benefits</h4>



<p><strong>High Quality</strong>: Professional photography, all free&nbsp;<strong>Huge Library</strong>: Over 3 million images&nbsp;<strong>Legal Safety</strong>: Completely free for commercial use&nbsp;<strong>Developer-Friendly</strong>: Well-documented API&nbsp;<strong>SEO Value</strong>: Proper attribution builds credibility</p>



<p>According to&nbsp;<a href="https://unsplash.com/about">Unsplash</a>, images are downloaded&nbsp;<strong>over 10 billion times</strong>&nbsp;per year. It&#8217;s the go-to source for professional content creators.</p>



<h3 class="wp-block-heading" id="prerequisites-prerequisites">Prerequisites</h3>



<p>Before integrating Unsplash API, ensure you have:</p>



<h4 class="wp-block-heading" id="required-software">Required Software</h4>



<ul class="wp-block-list">
<li><strong>WP-CLI installed</strong>&nbsp;&#8211;&nbsp;<a href="#">Installation guide</a></li>



<li><strong>curl</strong>&nbsp;&#8211; For API requests</li>



<li><strong>jq</strong>&nbsp;&#8211; JSON parsing tool</li>



<li><strong>Bash</strong>&nbsp;&#8211; Shell scripting knowledge</li>
</ul>



<p>Install missing tools:</p>



<pre class="wp-block-code"><code><em># Ubuntu/Debian</em>
sudo apt-get install curl jq

<em># macOS</em>
brew install curl jq
</code></pre>



<h4 class="wp-block-heading" id="wordpress-requirements">WordPress Requirements</h4>



<ul class="wp-block-list">
<li>WordPress site with WP-CLI access</li>



<li>Write permissions for uploads directory</li>



<li>Basic understanding of&nbsp;<a href="https://wordpress.org/support/article/media-library-screen/">WordPress media library</a></li>
</ul>



<h4 class="wp-block-heading" id="bash-knowledge">Bash Knowledge</h4>



<p>Helpful background:</p>



<ul class="wp-block-list">
<li><a href="#">Bash functions for WordPress</a></li>



<li>API requests with curl</li>



<li>JSON parsing basics</li>
</ul>



<h3 class="wp-block-heading" id="getting-unsplash-api-access-api-access">Getting Unsplash API Access</h3>



<h4 class="wp-block-heading" id="step-1-create-unsplash-account">Step 1: Create Unsplash Account</h4>



<ol class="wp-block-list">
<li>Visit&nbsp;<a href="https://unsplash.com/">Unsplash.com</a></li>



<li>Sign up for free account</li>



<li>Verify your email</li>
</ol>



<h4 class="wp-block-heading" id="step-2-register-your-application">Step 2: Register Your Application</h4>



<ol class="wp-block-list">
<li>Go to&nbsp;<a href="https://unsplash.com/developers">Unsplash Developers</a></li>



<li>Click &#8220;Register as a Developer&#8221;</li>



<li>Accept the API terms</li>



<li>Click &#8220;New Application&#8221;</li>
</ol>



<h4 class="wp-block-heading" id="step-3-create-api-application">Step 3: Create API Application</h4>



<p>Fill in application details:</p>



<ul class="wp-block-list">
<li><strong>Application name</strong>: &#8220;WordPress Blog Automation&#8221;</li>



<li><strong>Description</strong>: &#8220;Automated featured image fetching for WordPress blog&#8221;</li>



<li><strong>Callback URLs</strong>: (not needed for this use case)</li>
</ul>



<p><strong>Important</strong>: Accept the&nbsp;<a href="https://help.unsplash.com/en/articles/2511245-unsplash-api-guidelines">API Guidelines</a></p>



<h4 class="wp-block-heading" id="step-4-get-api-keys">Step 4: Get API Keys</h4>



<p>After creating your app, you&#8217;ll receive:</p>



<ul class="wp-block-list">
<li><strong>Access Key</strong>: Public key for API requests (Demo: Limited to 50 requests/hour)</li>



<li><strong>Secret Key</strong>: Keep private (not needed for basic usage)</li>
</ul>



<p><strong>Demo vs Production:</strong></p>



<ul class="wp-block-list">
<li><strong>Demo</strong>: 50 requests/hour (good for testing)</li>



<li><strong>Production</strong>: 5,000 requests/hour (requires app approval by Unsplash)</li>
</ul>



<p>For most blogs, demo limits are sufficient. Production approval takes 1-2 business days.</p>



<h4 class="wp-block-heading" id="step-5-store-api-key-securely">Step 5: Store API Key Securely</h4>



<p><strong>Never hardcode API keys in scripts.</strong></p>



<p>Store in environment variable:</p>



<pre class="wp-block-code"><code><em># Add to ~/.bashrc or ~/.bash_profile</em>
export UNSPLASH_ACCESS_KEY="your_access_key_here"

<em># Reload</em>
source ~/.bashrc
</code></pre>



<p>Or use a config file:</p>



<pre class="wp-block-code"><code><em># Create config file</em>
nano ~/.unsplash-config

<em># Add key</em>
UNSPLASH_ACCESS_KEY=your_access_key_here

<em># Secure it</em>
chmod 600 ~/.unsplash-config
</code></pre>



<h3 class="wp-block-heading" id="understanding-unsplash-api-api-basics">Understanding Unsplash API</h3>



<h4 class="wp-block-heading" id="api-endpoints">API Endpoints</h4>



<p><strong>Search Photos:</strong></p>



<pre class="wp-block-code"><code>GET https://api.unsplash.com/search/photos
</code></pre>



<p><strong>Get Random Photo:</strong></p>



<pre class="wp-block-code"><code>GET https://api.unsplash.com/photos/random
</code></pre>



<p><strong>Get Specific Photo:</strong></p>



<pre class="wp-block-code"><code>GET https://api.unsplash.com/photos/{id}
</code></pre>



<h4 class="wp-block-heading" id="basic-api-request">Basic API Request</h4>



<pre class="wp-block-code"><code>curl -H "Authorization: Client-ID YOUR_ACCESS_KEY" \
	"https://api.unsplash.com/photos/random?query=nature"
</code></pre>



<h4 class="wp-block-heading" id="response-format">Response Format</h4>



<p>Unsplash returns JSON:</p>



<pre class="wp-block-code"><code>{
	"id": "abc123",
	"urls": {
		"raw": "https://images.unsplash.com/photo-...",
		"full": "https://images.unsplash.com/photo-...",
		"regular": "https://images.unsplash.com/photo-...",
		"small": "https://images.unsplash.com/photo-..."
	},
	"user": {
		"name": "John Doe",
		"username": "johndoe",
		"links": {
			"html": "https://unsplash.com/@johndoe"
		}
	},
	"description": "Beautiful sunset over mountains",
	"alt_description": "orange sunset"
}
</code></pre>



<p><strong>Key fields:</strong></p>



<ul class="wp-block-list">
<li><code>urls.regular</code>: Best for WordPress featured images (1080px wide)</li>



<li><code>user.name</code>: For attribution</li>



<li><code>user.links.html</code>: Link to photographer&#8217;s profile</li>



<li><code>alt_description</code>: Good for alt text</li>
</ul>



<p>Read full docs:&nbsp;<a href="https://unsplash.com/documentation">Unsplash API Documentation</a></p>



<h3 class="wp-block-heading" id="fetching-images-with-curl-fetching-images">Fetching Images with curl</h3>



<h4 class="wp-block-heading" id="search-for-images">Search for Images</h4>



<pre class="wp-block-code"><code>#!/bin/bash

UNSPLASH_KEY="your_access_key"
QUERY="technology"

<em># Search for images</em>
response=$(curl -s -H "Authorization: Client-ID ${UNSPLASH_KEY}" \
	"https://api.unsplash.com/search/photos?query=${QUERY}&amp;per_page=1")

<em># Parse response with jq</em>
image_url=$(echo "$response" | jq -r '.results&#91;0].urls.regular')
photo_id=$(echo "$response" | jq -r '.results&#91;0].id')
photographer=$(echo "$response" | jq -r '.results&#91;0].user.name')
photographer_url=$(echo "$response" | jq -r '.results&#91;0].user.links.html')
alt_text=$(echo "$response" | jq -r '.results&#91;0].alt_description')

echo "Image URL: ${image_url}"
echo "Photographer: ${photographer}"
echo "Alt Text: ${alt_text}"
</code></pre>



<h4 class="wp-block-heading" id="get-random-image">Get Random Image</h4>



<pre class="wp-block-code"><code>get_random_image() {
		local query=$1
		local orientation=${2:-landscape}  <em># landscape, portrait, squarish</em>

		local response=$(curl -s -H "Authorization: Client-ID ${UNSPLASH_KEY}" \
			"https://api.unsplash.com/photos/random?query=${query}&amp;orientation=${orientation}")

		echo "$response"
}

<em># Usage</em>
response=$(get_random_image "coding" "landscape")
image_url=$(echo "$response" | jq -r '.urls.regular')
</code></pre>



<h4 class="wp-block-heading" id="search-parameters">Search Parameters</h4>



<p>Common parameters:</p>



<pre class="wp-block-code"><code><em># Search with pagination</em>
?query=nature&amp;page=2&amp;per_page=10

<em># Filter by orientation</em>
?query=laptop&amp;orientation=landscape

<em># Filter by color</em>
?query=sunset&amp;color=orange

<em># Combine filters</em>
?query=workspace&amp;orientation=landscape&amp;color=black_and_white
</code></pre>



<p><strong>Orientation options:</strong></p>



<ul class="wp-block-list">
<li><code>landscape</code>&nbsp;&#8211; Horizontal (best for featured images)</li>



<li><code>portrait</code>&nbsp;&#8211; Vertical</li>



<li><code>squarish</code>&nbsp;&#8211; Square-ish</li>
</ul>



<p><strong>Color options:</strong></p>



<ul class="wp-block-list">
<li><code>black_and_white</code>,&nbsp;<code>black</code>,&nbsp;<code>white</code>,&nbsp;<code>yellow</code>,&nbsp;<code>orange</code>,&nbsp;<code>red</code>,&nbsp;<code>purple</code>,&nbsp;<code>magenta</code>,&nbsp;<code>green</code>,&nbsp;<code>teal</code>,&nbsp;<code>blue</code></li>
</ul>



<h3 class="wp-block-heading" id="downloading-images-downloading">Downloading Images</h3>



<h4 class="wp-block-heading" id="download-image-to-filesystem">Download Image to Filesystem</h4>



<pre class="wp-block-code"><code>download_image() {
		local image_url=$1
		local output_file=$2

		if curl -s -o "$output_file" "$image_url"; then
				echo "Downloaded: ${output_file}"
				return 0
		else
				echo "Error: Download failed" &gt;&amp;2
				return 1
		fi
}

<em># Usage</em>
image_url="https://images.unsplash.com/photo-xyz?w=1080"
output="/tmp/unsplash-image.jpg"

download_image "$image_url" "$output"
</code></pre>



<h4 class="wp-block-heading" id="generate-unique-filename">Generate Unique Filename</h4>



<pre class="wp-block-code"><code>generate_filename() {
		local query=$1
		local timestamp=$(date +%Y%m%d_%H%M%S)
		local random=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 6)

		<em># Sanitize query (remove spaces, special chars)</em>
		local clean_query=$(echo "$query" | tr ' ' '-' | tr -cd '&#91;:alnum:]-')

		echo "unsplash-${clean_query}-${timestamp}-${random}.jpg"
}

<em># Usage</em>
filename=$(generate_filename "mountain landscape")
<em># Output: unsplash-mountain-landscape-20250325_143022-aB3xY9.jpg</em>
</code></pre>



<h4 class="wp-block-heading" id="complete-download-function">Complete Download Function</h4>



<pre class="wp-block-code"><code>fetch_and_download() {
		local query=$1
		local output_dir=${2:-/tmp}

		<em># Fetch image data</em>
		local response=$(curl -s -H "Authorization: Client-ID ${UNSPLASH_KEY}" \
			"https://api.unsplash.com/photos/random?query=${query}&amp;orientation=landscape")

		<em># Parse response</em>
		local image_url=$(echo "$response" | jq -r '.urls.regular')
		local photo_id=$(echo "$response" | jq -r '.id')

		if &#91; "$image_url" = "null" ] || &#91; -z "$image_url" ]; then
				echo "Error: No image found for query '${query}'" &gt;&amp;2
				return 1
		fi

		<em># Generate filename</em>
		local filename=$(generate_filename "$query")
		local filepath="${output_dir}/${filename}"

		<em># Download image</em>
		if curl -s -o "$filepath" "$image_url"; then
				echo "$filepath"
				return 0
		else
				echo "Error: Download failed" &gt;&amp;2
				return 1
		fi
}

<em># Usage</em>
image_file=$(fetch_and_download "workspace" "/tmp")
echo "Image saved: ${image_file}"
</code></pre>



<h3 class="wp-block-heading" id="importing-to-wordpress-media-library-importing-media">Importing to WordPress Media Library</h3>



<h4 class="wp-block-heading" id="wp-cli-media-import">WP-CLI Media Import</h4>



<p>WP-CLI provides&nbsp;<code>wp media import</code>&nbsp;for adding images to media library.</p>



<p><strong>Basic import:</strong></p>



<pre class="wp-block-code"><code>wp media import /tmp/image.jpg --title="My Image"
</code></pre>



<p><strong>With metadata:</strong></p>



<pre class="wp-block-code"><code>wp media import /tmp/image.jpg \
	--title="Mountain Landscape" \
	--alt="Beautiful mountain sunset" \
	--caption="Photo by John Doe on Unsplash" \
	--porcelain  <em># Returns attachment ID only</em>
</code></pre>



<h4 class="wp-block-heading" id="import-function-with-metadata">Import Function with Metadata</h4>



<pre class="wp-block-code"><code>import_to_wordpress() {
		local image_file=$1
		local title=$2
		local alt_text=$3
		local caption=$4

		<em># Import and get attachment ID</em>
		local attachment_id=$(wp media import "$image_file" \
				--title="$title" \
				--alt="$alt_text" \
				--caption="$caption" \
				--porcelain)

		if &#91; -n "$attachment_id" ]; then
				echo "Imported as attachment ID: ${attachment_id}"
				echo "$attachment_id"
				return 0
		else
				echo "Error: Import failed" &gt;&amp;2
				return 1
		fi
}

<em># Usage</em>
attachment_id=$(import_to_wordpress \
		"/tmp/image.jpg" \
		"Tech Workspace" \
		"Modern laptop on wooden desk" \
		"Photo by Jane Smith on Unsplash")
</code></pre>



<h4 class="wp-block-heading" id="complete-fetch-and-import">Complete Fetch and Import</h4>



<pre class="wp-block-code"><code>fetch_and_import() {
		local query=$1

		<em># Fetch image from Unsplash</em>
		local response=$(curl -s -H "Authorization: Client-ID ${UNSPLASH_KEY}" \
			"https://api.unsplash.com/photos/random?query=${query}&amp;orientation=landscape")

		<em># Parse metadata</em>
		local image_url=$(echo "$response" | jq -r '.urls.regular')
		local photographer=$(echo "$response" | jq -r '.user.name')
		local photographer_url=$(echo "$response" | jq -r '.user.links.html')
		local alt_text=$(echo "$response" | jq -r '.alt_description')
		local description=$(echo "$response" | jq -r '.description // .alt_description')

		<em># Download to temp file</em>
		local temp_file="/tmp/unsplash-$(date +%s).jpg"
		curl -s -o "$temp_file" "$image_url"

		<em># Prepare metadata</em>
		local title="$description"
		local caption="Photo by ${photographer} on Unsplash (${photographer_url})"

		<em># Import to WordPress</em>
		local attachment_id=$(wp media import "$temp_file" \
				--title="$title" \
				--alt="$alt_text" \
				--caption="$caption" \
				--porcelain)

		<em># Clean up temp file</em>
		rm -f "$temp_file"

		echo "$attachment_id"
}

<em># Usage</em>
attachment_id=$(fetch_and_import "coffee shop")
echo "Imported image: ${attachment_id}"
</code></pre>



<h3 class="wp-block-heading" id="setting-featured-images-featured-images">Setting Featured Images</h3>



<h4 class="wp-block-heading" id="set-featured-image-for-post">Set Featured Image for Post</h4>



<pre class="wp-block-code"><code>wp post meta update POST_ID _thumbnail_id ATTACHMENT_ID
</code></pre>



<p><strong>Example:</strong></p>



<pre class="wp-block-code"><code><em># Post ID 123, Attachment ID 456</em>
wp post meta update 123 _thumbnail_id 456
</code></pre>



<h4 class="wp-block-heading" id="complete-function">Complete Function</h4>



<pre class="wp-block-code"><code>set_featured_image() {
		local post_id=$1
		local attachment_id=$2

		if wp post meta update "$post_id" _thumbnail_id "$attachment_id" &amp;&gt;/dev/null; then
				echo "Featured image set for post ${post_id}"
				return 0
		else
				echo "Error: Failed to set featured image" &gt;&amp;2
				return 1
		fi
}

<em># Usage</em>
set_featured_image 123 456
</code></pre>



<h4 class="wp-block-heading" id="one-command-solution">One-Command Solution</h4>



<p>Combine everything:</p>



<pre class="wp-block-code"><code>set_unsplash_featured() {
		local post_id=$1
		local query=$2

		echo "Fetching image for: ${query}"

		<em># Fetch and import</em>
		local attachment_id=$(fetch_and_import "$query")

		if &#91; -z "$attachment_id" ]; then
				echo "Error: Failed to fetch/import image" &gt;&amp;2
				return 1
		fi

		<em># Set as featured</em>
		if set_featured_image "$post_id" "$attachment_id"; then
				echo "✓ Featured image set successfully"
				echo "Post ID: ${post_id}"
				echo "Attachment ID: ${attachment_id}"
				return 0
		else
				return 1
		fi
}

<em># Usage</em>
set_unsplash_featured 123 "technology workspace"
</code></pre>



<h3 class="wp-block-heading" id="handling-attribution-attribution">Handling Attribution</h3>



<h4 class="wp-block-heading" id="unsplash-attribution-requirements">Unsplash Attribution Requirements</h4>



<p>Per&nbsp;<a href="https://unsplash.com/license">Unsplash License</a>:</p>



<p><strong>Required:</strong></p>



<ul class="wp-block-list">
<li>Credit photographer by name</li>



<li>Link to photographer&#8217;s Unsplash profile</li>
</ul>



<p><strong>Good attribution:</strong></p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>&#8220;Photo by&nbsp;<a href="#">Photographer Name</a>&nbsp;on Unsplash&#8221;</p>
</blockquote>



<p><strong>Bad attribution:</strong></p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>&#8220;From Unsplash&#8221; (missing photographer credit)</p>
</blockquote>



<h4 class="wp-block-heading" id="add-attribution-to-caption">Add Attribution to Caption</h4>



<pre class="wp-block-code"><code>create_attribution() {
		local photographer=$1
		local photographer_url=$2

		echo "Photo by ${photographer} on Unsplash (${photographer_url})"
}

<em># Usage</em>
photographer="John Doe"
url="https://unsplash.com/@johndoe"
caption=$(create_attribution "$photographer" "$url")
<em># Output: Photo by John Doe on Unsplash (https://unsplash.com/@johndoe)</em>
</code></pre>



<h4 class="wp-block-heading" id="add-attribution-to-post-content">Add Attribution to Post Content</h4>



<p>Optionally add attribution directly in post content:</p>



<pre class="wp-block-code"><code>add_attribution_to_post() {
		local post_id=$1
		local photographer=$2
		local photographer_url=$3

		<em># Get current content</em>
		local content=$(wp post get "$post_id" --field=content)

		<em># Append attribution</em>
		local attribution="&lt;p&gt;&lt;em&gt;Featured image by &lt;a href=\"${photographer_url}\"&gt;${photographer}&lt;/a&gt; on &lt;a href=\"https://unsplash.com\"&gt;Unsplash&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;"

		local new_content="${content}\n\n${attribution}"

		<em># Update post</em>
		wp post update "$post_id" --post_content="$new_content"
}
</code></pre>



<h4 class="wp-block-heading" id="trigger-download-tracking">Trigger Download Tracking</h4>



<p>Unsplash requires triggering download endpoint for analytics:</p>



<pre class="wp-block-code"><code>trigger_download() {
		local download_url=$1

		curl -s -H "Authorization: Client-ID ${UNSPLASH_KEY}" "$download_url" &gt; /dev/null
}

<em># Get download URL from API response</em>
download_url=$(echo "$response" | jq -r '.links.download_location')
trigger_download "$download_url"
</code></pre>



<p><strong>Important</strong>: This is required by Unsplash API guidelines.</p>



<h3 class="wp-block-heading" id="complete-automation-script-complete-script">Complete Automation Script</h3>



<p>Here&#8217;s the full production-ready script:</p>



<pre class="wp-block-code"><code>#!/bin/bash
<em>#</em>
<em># Unsplash WordPress Integration Script</em>
<em># Fetches images from Unsplash and sets as WordPress featured images</em>
<em>#</em>

set -euo pipefail

<em>#############################################</em>
<em># CONFIGURATION</em>
<em>#############################################</em>

<em># Load API key from config file</em>
if &#91; -f ~/.unsplash-config ]; then
		source ~/.unsplash-config
fi

UNSPLASH_KEY="${UNSPLASH_ACCESS_KEY:-}"
TEMP_DIR="/tmp/unsplash-wp"

<em>#############################################</em>
<em># FUNCTIONS</em>
<em>#############################################</em>

check_dependencies() {
		local missing=()

		command -v curl &amp;&gt;/dev/null || missing+=("curl")
		command -v jq &amp;&gt;/dev/null || missing+=("jq")
		command -v wp &amp;&gt;/dev/null || missing+=("wp-cli")

		if &#91;  then
				echo "Error: Missing dependencies: ${missing&#91;*]}" &gt;&amp;2
				exit 1
		fi

		if &#91; -z "$UNSPLASH_KEY" ]; then
				echo "Error: UNSPLASH_ACCESS_KEY not set" &gt;&amp;2
				echo "Set it in ~/.unsplash-config or environment" &gt;&amp;2
				exit 1
		fi
}

fetch_unsplash_image() {
		local query=$1
		local orientation=${2:-landscape}

		local url="https://api.unsplash.com/photos/random"
		url="${url}?query=${query}&amp;orientation=${orientation}"

		local response=$(curl -s -H "Authorization: Client-ID ${UNSPLASH_KEY}" "$url")

		<em># Check for errors</em>
		local errors=$(echo "$response" | jq -r '.errors // empty')
		if &#91; -n "$errors" ]; then
				echo "API Error: $errors" &gt;&amp;2
				return 1
		fi

		echo "$response"
}

download_image() {
		local image_url=$1
		local output_file=$2

		if curl -s -L -o "$output_file" "$image_url"; then
				return 0
		else
				return 1
		fi
}

import_to_media_library() {
		local image_file=$1
		local metadata=$2

		local title=$(echo "$metadata" | jq -r '.title')
		local alt=$(echo "$metadata" | jq -r '.alt')
		local caption=$(echo "$metadata" | jq -r '.caption')

		local attachment_id=$(wp media import "$image_file" \
				--title="$title" \
				--alt="$alt" \
				--caption="$caption" \
				--porcelain 2&gt;/dev/null)

		echo "$attachment_id"
}

set_featured_image_for_post() {
		local post_id=$1
		local attachment_id=$2

		wp post meta update "$post_id" _thumbnail_id "$attachment_id" &amp;&gt;/dev/null
}

trigger_download_endpoint() {
		local download_url=$1

		curl -s -H "Authorization: Client-ID ${UNSPLASH_KEY}" "$download_url" &gt; /dev/null
}

<em>#############################################</em>
<em># MAIN FUNCTION</em>
<em>#############################################</em>

set_unsplash_featured() {
		local post_id=$1
		local query=$2
		local orientation=${3:-landscape}

		echo "================================================"
		echo "Unsplash Featured Image Automation"
		echo "================================================"
		echo "Post ID: ${post_id}"
		echo "Query: ${query}"
		echo "Orientation: ${orientation}"
		echo "================================================"

		<em># Verify post exists</em>
		if ! wp post get "$post_id" &amp;&gt;/dev/null; then
				echo "Error: Post ${post_id} not found" &gt;&amp;2
				return 1
		fi

		<em># Fetch image from Unsplash</em>
		echo "Fetching image from Unsplash..."
		local response=$(fetch_unsplash_image "$query" "$orientation")

		if &#91; $? -ne 0 ]; then
				echo "Error: Failed to fetch image" &gt;&amp;2
				return 1
		fi

		<em># Parse response</em>
		local image_url=$(echo "$response" | jq -r '.urls.regular')
		local photographer=$(echo "$response" | jq -r '.user.name')
		local photographer_url=$(echo "$response" | jq -r '.user.links.html')
		local alt_text=$(echo "$response" | jq -r '.alt_description // "Image from Unsplash"')
		local description=$(echo "$response" | jq -r '.description // .alt_description')
		local download_endpoint=$(echo "$response" | jq -r '.links.download_location')

		echo "Found: ${description}"
		echo "By: ${photographer}"

		<em># Create temp directory</em>
		mkdir -p "$TEMP_DIR"

		<em># Download image</em>
		local temp_file="${TEMP_DIR}/unsplash-$(date +%s).jpg"
		echo "Downloading image..."

		if ! download_image "$image_url" "$temp_file"; then
				echo "Error: Download failed" &gt;&amp;2
				return 1
		fi

		<em># Prepare metadata</em>
		local caption="Photo by &lt;a href=\"${photographer_url}\"&gt;${photographer}&lt;/a&gt; on &lt;a href=\"https://unsplash.com\"&gt;Unsplash&lt;/a&gt;"

		local metadata=$(jq -n \
				--arg title "$description" \
				--arg alt "$alt_text" \
				--arg caption "$caption" \
				'{title: $title, alt: $alt, caption: $caption}')

		<em># Import to WordPress</em>
		echo "Importing to media library..."
		local attachment_id=$(import_to_media_library "$temp_file" "$metadata")

		if &#91; -z "$attachment_id" ]; then
				echo "Error: Import failed" &gt;&amp;2
				rm -f "$temp_file"
				return 1
		fi

		echo "Imported as attachment ${attachment_id}"

		<em># Set as featured image</em>
		echo "Setting as featured image..."
		if set_featured_image_for_post "$post_id" "$attachment_id"; then
				echo "✓ Featured image set successfully"
		else
				echo "Error: Failed to set featured image" &gt;&amp;2
				rm -f "$temp_file"
				return 1
		fi

		<em># Trigger download tracking (required by Unsplash)</em>
		trigger_download_endpoint "$download_endpoint"

		<em># Clean up</em>
		rm -f "$temp_file"

		echo "================================================"
		echo "SUCCESS!"
		echo "Post: ${post_id}"
		echo "Attachment: ${attachment_id}"
		echo "Photographer: ${photographer}"
		echo "================================================"

		return 0
}

<em>#############################################</em>
<em># SCRIPT ENTRY POINT</em>
<em>#############################################</em>

<em># Check dependencies</em>
check_dependencies

<em># Parse arguments</em>
if &#91; $# -lt 2 ]; then
		echo "Usage: $0 &lt;post_id&gt; &lt;search_query&gt; &#91;orientation]"
		echo ""
		echo "Examples:"
		echo "  $0 123 'technology workspace'"
		echo "  $0 456 'coffee shop' portrait"
		echo ""
		exit 1
fi

POST_ID=$1
QUERY=$2
ORIENTATION=${3:-landscape}

<em># Run main function</em>
set_unsplash_featured "$POST_ID" "$QUERY" "$ORIENTATION"

exit $?
</code></pre>



<h4 class="wp-block-heading" id="usage">Usage</h4>



<pre class="wp-block-code"><code><em># Save as unsplash-wp.sh</em>
chmod +x unsplash-wp.sh

<em># Set featured image for post</em>
./unsplash-wp.sh 123 "technology workspace"

<em># Portrait orientation</em>
./unsplash-wp.sh 456 "coffee shop interior" portrait

<em># Multiple keywords</em>
./unsplash-wp.sh 789 "mountain sunset landscape"
</code></pre>



<h3 class="wp-block-heading" id="advanced-features-advanced">Advanced Features</h3>



<h4 class="wp-block-heading" id="bulk-set-featured-images">Bulk Set Featured Images</h4>



<p>Process multiple posts:</p>



<pre class="wp-block-code"><code><em># Get all posts without featured images</em>
posts=$(wp post list --post_type=post --meta_key=_thumbnail_id --meta_compare=NOT EXISTS --field=ID)

for post_id in $posts; do
		<em># Get post title or category for query</em>
		title=$(wp post get $post_id --field=title)

		<em># Set featured image</em>
		./unsplash-wp.sh $post_id "$title"

		sleep 2  <em># Rate limiting</em>
done
</code></pre>



<h4 class="wp-block-heading" id="smart-query-from-post-content">Smart Query from Post Content</h4>



<p>Extract keywords from post:</p>



<pre class="wp-block-code"><code>get_query_from_post() {
		local post_id=$1

		<em># Get post title</em>
		local title=$(wp post get $post_id --field=title)

		<em># Get first category</em>
		local category=$(wp post term list $post_id category --field=name --format=csv | head -1)

		<em># Combine for better results</em>
		echo "${category} ${title}"
}

<em># Usage</em>
query=$(get_query_from_post 123)
./unsplash-wp.sh 123 "$query"
</code></pre>



<h4 class="wp-block-heading" id="fallback-to-default-images">Fallback to Default Images</h4>



<pre class="wp-block-code"><code>set_featured_with_fallback() {
		local post_id=$1
		local query=$2
		local fallback_query="abstract background"

		if ! ./unsplash-wp.sh $post_id "$query"; then
				echo "Primary query failed, trying fallback..."
				./unsplash-wp.sh $post_id "$fallback_query"
		fi
}
</code></pre>



<h3 class="wp-block-heading" id="error-handling-error-handling">Error Handling</h3>



<h4 class="wp-block-heading" id="api-error-responses">API Error Responses</h4>



<p>Handle common errors:</p>



<pre class="wp-block-code"><code>handle_api_response() {
		local response=$1

		<em># Check for rate limit</em>
		local rate_limit=$(echo "$response" | jq -r '.errors&#91;0] // empty' | grep -i "rate limit")
		if &#91; -n "$rate_limit" ]; then
				echo "Error: API rate limit reached" &gt;&amp;2
				echo "Wait 1 hour or upgrade to production API" &gt;&amp;2
				return 1
		fi

		<em># Check for invalid query</em>
		local invalid=$(echo "$response" | jq -r '.errors&#91;0] // empty')
		if &#91; -n "$invalid" ]; then
				echo "Error: $invalid" &gt;&amp;2
				return 1
		fi

		return 0
}
</code></pre>



<h4 class="wp-block-heading" id="network-errors">Network Errors</h4>



<pre class="wp-block-code"><code>download_with_retry() {
		local url=$1
		local output=$2
		local max_attempts=3
		local attempt=1

		while &#91; $attempt -le $max_attempts ]; do
				echo "Download attempt ${attempt}/${max_attempts}"

				if curl -s -L -o "$output" --connect-timeout 10 "$url"; then
						return 0
				fi

				attempt=$((attempt + 1))
				sleep 2
		done

		echo "Error: Download failed after ${max_attempts} attempts" &gt;&amp;2
		return 1
}
</code></pre>



<h3 class="wp-block-heading" id="rate-limiting-rate-limiting">Rate Limiting</h3>



<h4 class="wp-block-heading" id="unsplash-rate-limits">Unsplash Rate Limits</h4>



<ul class="wp-block-list">
<li><strong>Demo</strong>: 50 requests/hour</li>



<li><strong>Production</strong>: 5,000 requests/hour</li>
</ul>



<h4 class="wp-block-heading" id="implement-rate-limiting">Implement Rate Limiting</h4>



<pre class="wp-block-code"><code>check_rate_limit() {
		local last_request_file="/tmp/unsplash-last-request"
		local min_interval=72  <em># 50 requests/hour = 72 seconds between requests</em>

		if &#91; -f "$last_request_file" ]; then
				local last_request=$(cat "$last_request_file")
				local now=$(date +%s)
				local elapsed=$((now - last_request))

				if &#91; $elapsed -lt $min_interval ]; then
						local wait=$((min_interval - elapsed))
						echo "Rate limiting: waiting ${wait} seconds..."
						sleep $wait
				fi
		fi

		<em># Update last request time</em>
		date +%s &gt; "$last_request_file"
}

<em># Call before API requests</em>
check_rate_limit
</code></pre>



<h4 class="wp-block-heading" id="monitor-usage">Monitor Usage</h4>



<p>Check remaining requests:</p>



<pre class="wp-block-code"><code>response=$(curl -I -H "Authorization: Client-ID ${UNSPLASH_KEY}" \
	"https://api.unsplash.com/photos/random")

remaining=$(echo "$response" | grep -i "X-Ratelimit-Remaining" | cut -d: -f2 | tr -d ' \r')

echo "Remaining requests: ${remaining}"
</code></pre>



<h3 class="wp-block-heading" id="integration-with-publishing-pipeline-integration">Integration with Publishing Pipeline</h3>



<h4 class="wp-block-heading" id="automated-blog-publishing">Automated Blog Publishing</h4>



<p>Combine with content automation:</p>



<pre class="wp-block-code"><code>publish_post_with_image() {
		local title=$1
		local content=$2
		local query=$3

		<em># Create post</em>
		local post_id=$(wp post create \
				--post_title="$title" \
				--post_content="$content" \
				--post_status=publish \
				--porcelain)

		<em># Set featured image from Unsplash</em>
		./unsplash-wp.sh $post_id "$query"

		echo "Published post: ${post_id}"
}

<em># Usage</em>
publish_post_with_image \
		"10 Best Productivity Tools" \
		"Content here..." \
		"productivity workspace"
</code></pre>



<h4 class="wp-block-heading" id="integration-with-ai-content">Integration with AI Content</h4>



<pre class="wp-block-code"><code><em># Get AI-generated content</em>
content=$(call_ai_api "Write about productivity tools")

<em># Extract keywords for image</em>
keywords=$(echo "$content" | extract_keywords)  <em># Custom function</em>

<em># Create post</em>
post_id=$(wp post create --post_title="..." --post_content="$content" --porcelain)

<em># Set Unsplash featured image</em>
./unsplash-wp.sh $post_id "$keywords"
</code></pre>



<p>Learn more:&nbsp;<a href="#">Automated Blog Publishing with AI</a></p>



<h3 class="wp-block-heading" id="troubleshooting-troubleshooting">Troubleshooting</h3>



<h4 class="wp-block-heading" id="issue-1-jq-command-not-found">Issue 1: &#8220;jq: command not found&#8221;</h4>



<p><strong>Solution:</strong></p>



<pre class="wp-block-code"><code><em># Ubuntu/Debian</em>
sudo apt-get install jq

<em># macOS</em>
brew install jq

<em># CentOS</em>
sudo yum install jq
</code></pre>



<h4 class="wp-block-heading" id="issue-2-401-unauthorized">Issue 2: &#8220;401 Unauthorized&#8221;</h4>



<p><strong>Problem</strong>: Invalid API key</p>



<p><strong>Solutions:</strong></p>



<ol class="wp-block-list">
<li>Verify API key is correct</li>



<li>Check environment variable is set:</li>
</ol>



<pre class="wp-block-code"><code>echo $UNSPLASH_ACCESS_KEY
</code></pre>



<ol start="3" class="wp-block-list">
<li>Regenerate API key in Unsplash dashboard</li>
</ol>



<h4 class="wp-block-heading" id="issue-3-no-images-found">Issue 3: No Images Found</h4>



<p><strong>Problem</strong>: Query returns no results</p>



<p><strong>Solutions:</strong></p>



<ol class="wp-block-list">
<li>Simplify query (use broader terms)</li>



<li>Try different keywords</li>



<li>Check query isn&#8217;t too specific</li>
</ol>



<pre class="wp-block-code"><code><em># Too specific (may fail)</em>
query="red ferrari on mountain road at sunset"

<em># Better (broader)</em>
query="sports car"
</code></pre>



<h4 class="wp-block-heading" id="issue-4-rate-limit-exceeded">Issue 4: Rate Limit Exceeded</h4>



<p><strong>Problem</strong>: &#8220;Rate Limit Exceeded&#8221; error</p>



<p><strong>Solutions:</strong></p>



<ol class="wp-block-list">
<li>Wait 1 hour for demo API reset</li>



<li>Apply for production API (5,000 req/hour)</li>



<li>Implement rate limiting in your script</li>
</ol>



<h4 class="wp-block-heading" id="issue-5-import-failed">Issue 5: Import Failed</h4>



<p><strong>Problem</strong>:&nbsp;<code>wp media import</code>&nbsp;fails</p>



<p><strong>Solutions:</strong></p>



<ol class="wp-block-list">
<li>Check file permissions:</li>
</ol>



<pre class="wp-block-code"><code>ls -la /tmp/image.jpg
chmod 644 /tmp/image.jpg
</code></pre>



<ol start="2" class="wp-block-list">
<li>Verify uploads directory is writable:</li>
</ol>



<pre class="wp-block-code"><code>wp media regenerate --dry-run
</code></pre>



<ol start="3" class="wp-block-list">
<li>Check file size (Unsplash regular = ~500KB, should be fine)</li>
</ol>



<h3 class="wp-block-heading" id="next-steps-next-steps">Next Steps</h3>



<p>Congratulations! You&#8217;ve built a complete Unsplash + WordPress automation system.</p>



<h4 class="wp-block-heading" id="enhance-your-integration">Enhance Your Integration</h4>



<ol class="wp-block-list">
<li><strong><a href="#">Automated Blog Publishing Pipeline</a></strong>&nbsp;&#8211; Combine with AI content</li>



<li><strong><a href="#">Custom WP-CLI Commands</a></strong>&nbsp;&#8211; Build&nbsp;<code>wp unsplash</code>&nbsp;command</li>



<li><strong><a href="#">Bash Functions</a></strong>&nbsp;&#8211; Refactor into reusable library</li>
</ol>



<h4 class="wp-block-heading" id="related-guides">Related Guides</h4>



<ul class="wp-block-list">
<li><strong><a href="#"">WordPress REST API Integration</a></strong>&nbsp;&#8211; Advanced API techniques</li>



<li><strong><a href="#">AI Content Generation</a></strong>&nbsp;&#8211; Complete publishing automation</li>



<li><strong><a href="#">WordPress Automation</a></strong>&nbsp;&#8211; More automation examples</li>
</ul>



<h4 class="wp-block-heading" id="build-the-complete-pipeline">Build the Complete Pipeline</h4>



<p>This Unsplash integration is one piece of a complete automated publishing system:</p>



<ol class="wp-block-list">
<li>Generate content with AI</li>



<li><strong>Fetch featured image from Unsplash</strong>&nbsp;← You just learned this</li>



<li>Schedule and publish post</li>



<li>Optimize SEO automatically</li>
</ol>



<p><strong><a href="/#get-started">Join WPCLI Mastery</a></strong>&nbsp;to build the complete system:</p>



<ul class="wp-block-list">
<li>Full automated blog publishing pipeline</li>



<li>AI + Unsplash + WP-CLI integration</li>



<li>Production-ready scripts and templates</li>



<li>Early bird pricing ($99 vs $199)</li>
</ul>



<h3 class="wp-block-heading" id="conclusion">Conclusion</h3>



<p>Automating featured images with Unsplash API and WP-CLI saves hours of manual work while ensuring every post has professional, high-quality imagery. The script you built today can process thousands of posts automatically.</p>



<p><strong>Key takeaways:</strong></p>



<ul class="wp-block-list">
<li>Unsplash API provides free, high-quality images</li>



<li>curl + jq makes API integration simple</li>



<li>WP-CLI&nbsp;<code>media import</code>&nbsp;handles WordPress integration</li>



<li>Proper attribution is required (and easy to automate)</li>



<li>Rate limiting prevents API issues</li>



<li>Integration with publishing pipelines creates powerful automation</li>
</ul>



<p>The image automation you built today becomes even more powerful when combined with AI content generation for a complete hands-free publishing system.</p>



<p><strong>Ready to implement?</strong>&nbsp;Start with the complete script and customize for your workflow.</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<p><strong>Questions about Unsplash + WordPress automation?</strong>&nbsp;Drop a comment below!</p>



<p><strong>Found this helpful?</strong>&nbsp;Share with WordPress developers automating content.</p>



<p><strong>Next:</strong>&nbsp;Build a complete&nbsp;<a href="#">WordPress CI/CD pipeline with GitHub Actions</a>&nbsp;that includes automated image fetching.</p>
<p>The post <a href="https://wpclimastery.com/blog/integrate-unsplash-api-with-wordpress-using-wp-cli-and-bash/">Integrate Unsplash API with WordPress Using WP-CLI and Bash</a> appeared first on <a href="https://wpclimastery.com">WP-CLI Mastery</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
