Post Loops are a very powerful automation tool, allowing administrators run actions on multiple posts at once. If you’re not sure about how a loop may affect posts on your site, we highly recommend creating and running the recipe on a staging site first. Once run, there’s no way to undo the actions of a post loop.
Post Loops allow you to run actions in bulk on multiple posts that meet whatever criteria you set. If you’re familiar with User Loops, Post Loops work in an almost identical way, except they loop through posts (including custom post types).
Here are a few examples of recipes you could run with post types:
- Loop through a list of all products in a certain category and send key attributes to a Google Sheets report
- When there are staff changes, loop through all posts with a certain tag and update the post author
- Loop through all blog posts and append an affiliate disclosure
- Output a list of all articles in a certain category that haven’t been updated for more than 1 year and add the list to Airtable
- Update all courses in a certain category and assign a new price by targeting a post meta key
- Find all blog posts that don’t have an SEO description, send the post content to OpenAI to generate a new SEO summary, then update the posts with the new descriptions
Adding a post loop
To add a post loop to your recipe:
- Scroll to the Actions section of the recipe.
- Click Add.
- Click Post loop.
This adds an empty loop to your recipe. Next you can choose the criteria for posts you want to target in the loop. By default, new post loops will target blog posts, but you can change this and/or add additional post loop filters.
Targeting the right posts
Actions will be run on every post that meets your loop criteria, so make absolutely sure you target the right posts. The first step is to set up a loop filter.
The following post loop filters are available:
- A post has or does not have a specific meta key
- A post has or does not have a term in a taxonomy
- A post’s field meets a condition
- A post’s meta value meets a condition
- The post type is equal to a specific post type
Adding loop filters makes loops run more efficiently, so if you can narrow your post targets with filters, you should.
Adding actions and tokens inside loops
Actions inside a post loop will be run for each post that meets the loop’s filter criteria.
How these work, however, is different than in User loops. Where in user loops the actions will automatically run on the user in the current loop iteration, for post loops you may need to tell the action which post to target. That’s why Post loops support an additional token category: Loops.
In the Loop token category you will find key tokens related to the post, like Post ID, Post title, Post status and more. Here’s what it will look like:
Suppose you have a post loop that runs a “Set post meta” action in bulk on all course post types. When the action runs, it needs to know which post to update, so inside the action we need to pass in the post ID related to that loop iteration. That means we would pass in the “Post ID” token from the loop token section above to the post we need to target by selecting the custom value option:
After selecting the option to use a custom value and populating the correct post ID, the action would then look like this, which allows us to target the specific post linked to the current loop iteration as it runs:
Triggering the loop
To run the bulk actions inside a loop, you need to trigger the recipe. You can use any supported trigger to run the loop, just like a regular recipe. Use Run now trigger to run actions on posts in bulk right from inside the recipe page.
Monitoring the progress of a loop
Once the recipe containing the post loop has been triggered, you can monitor the progress of the loop from Automator > Logs and view results in the easy-to-read, detailed logs.
Cancelling a loop
A cancel button lets you cancel a loop in progress. Loops are processed in batches (see Things to know, below) that are automatically sized to adapt to your specific server’s hardware. Cancelling a loop in progress will cancel batches that have not started yet; however the in-progress batch will continue to execute until it is completed.
Viewing loop results
Once the loop has completed, you can expand the log to see the result of each action on each post in the loop. This gives you very detailed information about posts that experienced an error or did meet the loop criteria, so you can easily trace any issues.
- There is no way to undo the actions that were executed in a loop, so be 100% sure your loop is correct before running. Consider testing on a staging site prior to running an extensive loop on your live site.
- When running loops with app actions (such as Google Sheets), you may run into rate limitations on the receiving side, which will cause actions to fail. While very rare, extremely large batches should in some cases be divided up.
Under the Hood
- Loops run as background processes. Loops are designed to be as efficient as possible and should not result in a performance hit to the front end of your site.
- Since loops run in the background, actions not in a loop will typically complete before the loop. If you want an action in a recipe to run after a loop completes, the only way to do that is to manually specify a delay for the action.
- Loops are executed in batches. The size and frequencies of these batches automatically adapt to your server’s capabilities and cannot be adjusted manually.
- You can stop a loop that’s in progress from the logs. However, an in-progress batch cannot by halted and will run to completion. Any batches not yet started will be cancelled.
- How long a loop takes to complete will depend on many factors, including:
- The number of posts the loop iterates over
- The number of filters inside the loop
- The number of actions inside the loop
- The type of actions inside the loop (some actions are slower than others)
- The capabilities of the server hosting the site