<?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>REST API Archives ~ Carlos Guzman</title>
	<atom:link href="https://carlosguzman.dev/tag/rest-api/feed/" rel="self" type="application/rss+xml" />
	<link>https://carlosguzman.dev/tag/rest-api/</link>
	<description>Web developer</description>
	<lastBuildDate>Tue, 03 Mar 2026 03:57:12 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://carlosguzman.dev/wp-content/uploads/2019/06/favicon.ico</url>
	<title>REST API Archives ~ Carlos Guzman</title>
	<link>https://carlosguzman.dev/tag/rest-api/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Building a WordPress plugin with modern architecture</title>
		<link>https://carlosguzman.dev/building-a-wordpress-plugin-with-modern-architecture/</link>
		
		<dc:creator><![CDATA[Carlos Guzmán]]></dc:creator>
		<pubDate>Thu, 15 Jan 2026 21:03:36 +0000</pubDate>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[phpunit]]></category>
		<category><![CDATA[React.js]]></category>
		<category><![CDATA[REST API]]></category>
		<category><![CDATA[Web Development]]></category>
		<guid isPermaLink="false">https://carlosguzman.dev/?p=281</guid>

					<description><![CDATA[<p>The Motivation: Why Build Another Crypto Plugin? When building a portfolio project, the &#8220;what&#8221; is often less important than the &#8220;how&#8221;. I decided building a WordPress plugin with modern architecture and I chose to build a Multi-Crypto Price Converter not because the market lacked one, but because it provided the perfect sandbox to demonstrate and [&#8230;]</p>
<p>The post <a href="https://carlosguzman.dev/building-a-wordpress-plugin-with-modern-architecture/">Building a WordPress plugin with modern architecture</a> appeared first on <a href="https://carlosguzman.dev">Carlos Guzman</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading"><strong>The Motivation: Why Build Another Crypto Plugin?</strong></h2>



<p>When building a portfolio project, the &#8220;what&#8221; is often less important than the &#8220;how&#8221;. I decided building a WordPress plugin with modern architecture and I chose to build a <strong>Multi-Crypto Price Converter</strong> not because the market lacked one, but because it provided the perfect sandbox to demonstrate and include in my portfolio how <strong>WordPress engineering</strong> looks like. While the feature set is straightforward, the architecture behind it is designed for scale, stability, and maintainability.</p>



<p>The goal was simple: Create a lightweight, robust, and highly maintainable plugin using modern tools like <strong>TypeScript, React, and SOLID PHP principles.</strong></p>



<h2 class="wp-block-heading"><strong>1. A Decoupled Architecture</strong></h2>



<p>Most WordPress plugins suffer from &#8220;hook fatigue,&#8221; where logic is scattered and hard to test. I approached this project with a clear separation of concerns:</p>



<ul class="wp-block-list">
<li><strong>The Backend (PHP):</strong> I implemented a <strong>Service Container</strong> and used <strong>Dependency Injection</strong> to manage my classes. The backend’s primary responsibility is data orchestration—fetching crypto prices from external APIs and managing a custom <strong>caching layer</strong>. By using a dedicated service for caching, I ensure that visitors hit my local REST API rather than exhausting external API limits. By coding to interfaces rather than concrete classes, the system is prepared for future-proofing (e.g., swapping out a price API without touching the core logic).</li>



<li><strong>The Frontend (React):</strong> To keep the experience snappy, the actual currency conversion happens on the client side. Once the React component fetches the cached prices from the WordPress REST API, it handles all calculations locally. This reduces server overhead and provides an instantaneous UI for the user.</li>
</ul>



<h2 class="wp-block-heading"><strong>2. Building &#8220;Bulletproof&#8221; Software with PHP-Scoper</strong></h2>



<p>In the WordPress ecosystem, dependency conflicts are a silent killer (e.g., your plugin uses Guzzle 7, but another plugin loads Guzzle 6). To prevent this, I used <strong>PHP-Scoper</strong>.</p>



<p>I’ve ensured that the plugin uses prefixes for third-party namespaces to make it completely isolated. It doesn&#8217;t matter what other plugins are installed; my dependencies will never conflict. This is a standard I believe should be used in all high-level WordPress development.</p>



<h2 class="wp-block-heading"><strong>3. Modern Frontend &amp; Gutenberg Integration</strong></h2>



<p>I wanted to showcase my experience with the modern WordPress block editor. The plugin includes a custom <strong>Gutenberg Block</strong> built with <strong>TypeScript</strong> and <strong>React</strong>.</p>



<ul class="wp-block-list">
<li><strong>Editor Experience:</strong> A custom Gutenberg block built with React and TypeScript for a native editing experience.</li>



<li><strong>Frontend Performance:</strong>  While I initially considered Vanilla JS, I pivoted to a <strong>React-based frontend component</strong> to handle the state of price conversions more elegantly and provide a smoother UX but mainly to showcase my experience creating React components. By moving the conversion math to React, I avoided unnecessary admin-ajax or REST calls during user interaction.</li>



<li><strong>REST API Integration:</strong> I built custom REST endpoints to handle data fetching, this decouples the frontend from the backend logic.</li>
</ul>



<h2 class="wp-block-heading"><strong>4. AI-Augmented Engineering</strong></h2>



<p>I used an AI coding assistant as a co-pilot for this project. My goal was to see how much it could accelerate my workflow.</p>



<ul class="wp-block-list">
<li><strong>The Result:</strong> It significantly sped up boilerplate and initial implementations.</li>



<li><strong>The Caveat:</strong> It requires a human hand. I found that while the AI is fast, I had to refactor its output to meet my architectural standards, fix edge-case validations, or pivot when I realized a design needed to change (such as switching from a Vanilla JS table to a full React component). I remained the architect; the AI was the builder. By maintaining a strict &#8220;Human-in-the-loop&#8221; approach—including detailed code reviews and manual refactoring—I was able to code faster without sacrificing the integrity of the architecture or losing control and knowledge of the details of the architecture.</li>
</ul>



<h2 class="wp-block-heading"><strong>5. Quality Assurance &amp; Tooling</strong></h2>



<p>Even for a portfolio piece, code quality is non-negotiable.</p>



<ul class="wp-block-list">
<li><strong>Unit Testing:</strong> I implemented tests for the core PHP logic, specifically focusing on the external API requests and the caching mechanism.</li>



<li><strong>Static Analysis &amp; Type Safety:</strong> To reduce bugs in the codebase, I utilized <strong>PHP 8</strong> features with <strong>strict typing</strong> throughout the plugin. I integrated <strong>PHPStan</strong> into my workflow to catch potential edge cases and type mismatches before the code ever reached execution, ensuring a level of type safety rarely seen in traditional WordPress development.</li>



<li><strong>Coding Standards:</strong> The project enforces <strong>PHPCS</strong> (WordPress standards) and <strong>ESLint</strong> to ensure the code is clean and readable for any developer who touches it next.</li>



<li><strong>Build Automation:</strong> Using <code>package.json</code> and <code>composer</code>, I created a streamlined local build process that orchestrates <code>tsc</code>, <code>wp-scripts</code>, and dependency scoping into a production-ready ZIP file.</li>
</ul>



<ul class="wp-block-list"></ul>



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



<h2 class="wp-block-heading"><strong>Summary</strong></h2>



<p>This project was a great way to combine my interest in Web3 with my experience in modern software design. It’s not just a price converter—it’s a demonstration of <strong>SOLID principles</strong>, <strong>dependency isolation</strong>, and a <strong>modern React-to-REST workflow</strong>.</p>



<p><strong><a target="_blank" rel="noreferrer noopener" href="https://github.com/c24o/wp-multi-crypto-price-converter">View the Source Code on GitHub</a></strong></p>



<h3 class="wp-block-heading">Multi Crypto Price Converter in Action</h3>


		<div class="wp-block-multi-crypto-price-converter-converter" data-coins="btc,eth,sol,trx,xrp,bnb,doge,ada,xmr,xlm,ltc,zec,hype">
							<div class="mcpc-converter-container"></div>
						<p>Data provided by <a href="https://www.coingecko.com/" target="_blank" rel="noopener noreferrer">CoinGecko</a></p>
							</div>
		<p>The post <a href="https://carlosguzman.dev/building-a-wordpress-plugin-with-modern-architecture/">Building a WordPress plugin with modern architecture</a> appeared first on <a href="https://carlosguzman.dev">Carlos Guzman</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>How to update meta fields of multiple posts in WordPress using a single REST request</title>
		<link>https://carlosguzman.dev/update-meta-fields-of-multiple-posts-in-wordpress-with-the-rest-api/</link>
					<comments>https://carlosguzman.dev/update-meta-fields-of-multiple-posts-in-wordpress-with-the-rest-api/#respond</comments>
		
		<dc:creator><![CDATA[Carlos Guzmán]]></dc:creator>
		<pubDate>Sat, 05 Oct 2024 17:10:51 +0000</pubDate>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[REST API]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[WordPress Batch Framework]]></category>
		<guid isPermaLink="false">https://carlosguzman.dev/?p=239</guid>

					<description><![CDATA[<p>Building a custom settings page in WordPress using React, I faced the situation where I wanted to update meta fields of multiple posts at once. I want to share the approach I used with the WordPress REST API. The WordPress REST API has a framework for making a series of REST API calls at once. [&#8230;]</p>
<p>The post <a href="https://carlosguzman.dev/update-meta-fields-of-multiple-posts-in-wordpress-with-the-rest-api/">How to update meta fields of multiple posts in WordPress using a single REST request</a> appeared first on <a href="https://carlosguzman.dev">Carlos Guzman</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Building a custom settings page in WordPress using React, I faced the situation where I wanted to update meta fields of multiple posts at once. I want to share the approach I used with the WordPress REST API.</p>



<p>The WordPress REST API has a framework for making a series of REST API calls at once. It is handy to update meta fields of multiple posts using a single REST request. The framework name is <a href="https://make.wordpress.org/core/2020/11/20/rest-api-batch-framework-in-wordpress-5-6/" target="_blank" rel="noreferrer noopener">REST API Batch Framework</a>. Next are the steps I took to use it.</p>



<h2 class="wp-block-heading">Registration of the meta fields in the REST API</h2>



<p>First I registered the custom meta field in the REST API using the <a href="https://developer.wordpress.org/reference/functions/register_post_meta/" target="_blank" rel="noreferrer noopener">register_post_meta</a> function.</p>



<pre class="wp-block-code"><code lang="php" class="language-php line-numbers">add_action( 'init', function() {
	register_post_meta(
		'post',
		'my_custom_field_name',
		[
			'single'       =&gt; true,
			'type'         =&gt; 'string',
			'show_in_rest' =&gt;  true,
		]
	);
} );</code></pre>



<ul class="wp-block-list">
<li>The first argument I used here is <code>'post'</code>, which means that the custom field is applied for items saved in the posts table (posts, pages and custom post types). Here you can use other entities like <code>'comment'</code>, <code>'term'</code> or <code>'user'</code>. If the meta field is used in a custom post type, then the custom post type should support custom fields. During the <a href="https://developer.wordpress.org/reference/functions/register_post_type/" target="_blank" rel="noreferrer noopener">custom post type registration</a>, you can use the <code>supports</code> field to add <code>custom-fields</code>.</li>



<li>The second argument is <code>'my_custom_field_name'</code> which is the key name used for the meta field.</li>



<li>The last argument describes the meta field. In this example, the meta field has one value per post only, its type is string and its value is accessible via the REST API. Indeed, the value of the <code>'show_in_rest'</code> key can be an array with the key <code>'schema'</code> to describe its data structure in the REST API.</li>
</ul>



<h2 class="wp-block-heading">Using the Batch Framework to update meta fields of multiple posts in WordPress</h2>



<p>The React component uses the Batch Framework and it is in charge of doing the request to update the posts. It has a function to update the meta fields of multiple posts in WordPress using a single request. The request looks like this:</p>



<pre class="wp-block-code"><code lang="typescript" class="language-typescript line-numbers">const requests = [
	{
		path: '/wp/v2/posts/10',
		method: 'POST',
		body: {
			meta: {
				my_custom_field_name: 'hello world',
			},
		},
	},
	{
		path: '/wp/v2/posts/11',
		method: 'POST',
		body: {
			meta: {
				my_custom_field_name: 'lorem ipsum...',
			},
		},
	},
	{
		path: '/wp/v2/posts/12',
		method: 'POST',
		body: {
			meta: {
				my_custom_field_name: '123abc',
			},
		},
	}
];
apiFetch( {
	path: 'batch/v1',
	method: 'POST',
	data: { requests },
} )
	.then( response =&gt; handleBatchResponse( response, requests ) )
	.catch( err =&gt; console.log( err ) );</code></pre>



<p>The <code><a href="https://developer.wordpress.org/block-editor/reference-guides/packages/packages-api-fetch/">apiFetch</a></code> call use the next config object:</p>



<ul class="wp-block-list">
<li>The <code>path</code> and the <code>method</code> properties of the Batch Framework endpoint, <code>batch/v1</code> and <code>POST</code> respectively.</li>



<li>The <code>data</code> property is an object with the property <code>requests</code> which contains an array with the configuration of each one of the requests we want to execute. Each configuration is an object with the required property <code>path</code> and optionally the properties <code>method</code>, <code>headers</code> and <code>body</code>. In this case, these are the configuration to make the requests to <a href="https://developer.wordpress.org/rest-api/reference/posts/#update-a-post" target="_blank" rel="noreferrer noopener">the WordPress endpoint <code>POST /wp/v2/posts/&lt;id&gt;</code></a> to update the posts.</li>
</ul>



<h2 class="wp-block-heading">Handling the response</h2>



<p>Finally here is how to handle the response of the request to update meta fields of multiple posts in WordPress. In the React component, I defined the next function:</p>



<pre class="wp-block-code"><code lang="typescript" class="language-typescript line-numbers">const handleBatchResponse = ( batchResponse, requests ) =&gt; {
	batchResponse.responses.forEach( ( requestResponse, idx ) =&gt; {
		// Get the data of the request related to the current response.
		const requestData = requests[ idx ];

		// Check if the response was not successful.
		if ( 200 !== requestResponse.status ) {
			// Show error message here.
		}
	} );
} );</code></pre>



<p>The custom function <code>handleBatchResponse</code> expects 2 parameters, the response of the batch request and the array of requests sent in the batch request. This function is called when the response of the request is received and parsed by the <code>apiFetch</code> call. The response of the batch requests is an object with the property <code>responses</code> which is an array of enveloped responses objects for each one of the requests sent in the batch request. Each enveloped response has the properties <code>status</code>, <code>headers</code> and <code>body</code>. The order of the items in the <code>responses</code> array corresponds to the order of the items in the <code>requests</code> array sent in the batch request, so the first object in <code>batchResponses.responses</code> is the response of the first object in the <code>requests</code> array.</p>



<h2 class="wp-block-heading">Conclusion</h2>



<p>It is possible to update meta fields of multiple posts in WordPress using a single REST requests. The REST API Batch Framework allows to run multiple requests at once in WordPress. However, take into account that it accepts up to 25 requests in a single batch. Additionally, the framework doesn&#8217;t support GET requests. Using parallel requests or <a href="https://developer.wordpress.org/rest-api/using-the-rest-api/linking-and-embedding/" target="_blank" rel="noreferrer noopener">linking and embedding</a> are the recommendation in this case.</p>
<p>The post <a href="https://carlosguzman.dev/update-meta-fields-of-multiple-posts-in-wordpress-with-the-rest-api/">How to update meta fields of multiple posts in WordPress using a single REST request</a> appeared first on <a href="https://carlosguzman.dev">Carlos Guzman</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://carlosguzman.dev/update-meta-fields-of-multiple-posts-in-wordpress-with-the-rest-api/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Page Caching using Disk: Enhanced 
Minified using Disk
Database Caching 34/44 queries in 0.008 seconds using Disk

Served from: carlosguzman.dev @ 2026-06-10 07:37:50 by W3 Total Cache
-->