REST API

WordPress REST API was added in version 4.7 and became the ground not only for Gutenberg block editor but also for headless web applications built on the base of WP. My crossposting plugin, for example, uses it to interact between two standalone WordPress websites.

Below you can find the tutorials about both WordPress and WooCommerce REST APIs.

How to Auto-Post From One WordPress Site to Another

In this tutorial I am going to show you how you can automatically post an article to another WordPress website with the help of a couple of hooks and REST API. There is also an alternative way of doing that with my Simple WP Crossposting plugin, we’re also going to cover in just a little bit.

By the way, in the similar tutorials about this topic it is usually recommended to use a RSS feed and a plugin which allows to import the content from a feed. Well, this may work when your post consists only from a title and some content but it won’t work of course for complex posts with custom fields, featured images etc.

How to Update Post Meta with WordPress REST API

This tutorial is an addition to my another tutorial about creating posts using REST API in WordPress, because in that post I didn’t mention how to work with meta fields. So now we’re going to add (or update) meta fields of a specific post with the help of REST API requests.

By the way, the whole process is similar when you work for example with term meta, not only with post meta.

Prevent Posts in the Trash from Being Updated via REST API

This is a very specific post so it may not be useful for many of you guys, but on the other hand I didn’t even find I hint about anything like this across the internet, so, for those of you who need it, this tutorial is a gem. I hope 🙂

Let’s say that you have my Simple WP Crossposting plugin installed on your main site (Site 1) or it could be any custom functionality or a plugin that uses a post update REST API endpoint {WP url}/wp-json/wp/v2/posts/{post ID}. So basically we’re syncing changes between the same posts on “Site 1” and “Site 2”.

And our goal is to prevent syncing changes we made on “Site 1” when a post copy on “Site 2” has been moved to the trash. Please note that here I mean not only restoring a post from the trash (changing the post status) but any changes.

How to Sync WooCommerce Products Between Sites

In this tutorial you will find two ways how you can use WooCommerce API to perform the product sync with multiple WooCommerce stores.

  1. Updating a product with the same SKU on another WooCommerce store automatically when it has been edited by a shop manager on the “Main store”. You can decide whether you would like to update a specific product data or all product data. And it is what we are going to do in this tutorial with code or with my WooCommerce product sync plugin.
  2. Updating product stock statuses and quantities on other WooCommerce stores not only when this product has been updated by shop managers but also when the product has been purchased (and its quantity was descreased, obviously). We are going to talk a little bit about it in this tutorial as well, but I recommend you to take a look at my another plugin which is intended to help you with that.

In case you decided to sync products between sites with the help of my plugin, a metabox “Publish on” will appear on your product pages in WordPress admin, just like this:

WooCommerce API product sync with multiple stores
This is how my WooCommerce product sync plugin works but you can also use the code option from this tutorial.

How to Copy a Page from One WordPress Site to Another

In this tutorial I would like to cover two ways how you can copy a WordPress page from one site to another. I am not going to use the export and import approach, because I think it is too complicated and requires extra steps which we normally don’t need.

And of course everything in this tutorial applies not only to regular WordPress pages, but also:

  • pages with tons of custom fields (ACF, Carbon Fields, Simple Fields etc),
  • pages, created with page builders (Elementor, WPBakery, Beaver Builder etc).
  • pages, created with either classic or the block editor.

So let’s get started now.

Upload Featured Image to a Post with REST API

Recently I have updated the tutorial about creating a post with WordPress REST API but I didn’t cover a topic of featured images there. Or not exactly a featured image, it works the same when you want to upload any image with REST API.

It is not that simple actually, but I will make it simple for you.

Disable REST API without Plugins

Before I provide you a code snippet which you can copy and paste to your functions.php or something I would like to discuss why do even need to disable JSON REST API in WordPress?

The long story short is to provide less information about your website to those who shouldn’t probably have it. For example if we add at the end of site URL /wp-json/wp/v2/users, we can list all the registered users! Without emails of course but anyway.

If you want to prevent this from hapenning, you can either disable WordPress REST API completely or just its specific endpoints. And that’s what we’re going to do in this guide.