перейти до основного вмісту

Петлі постів

УВАГА!

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:

  1. Scroll to the Actions section of the recipe.
  2. Click Add.
  3. Click Post loop.

Add a 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.

Post Loop Filters

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.

Додавання дій та токенів усередині циклів

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.

Loop tokens

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:

Loop tokens for Automator

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:

Update courses in a loop

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:

Custom post ID for a 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.

Моніторинг прогресу циклу

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.

Скасування циклу

Кнопка скасування дозволяє скасувати поточний цикл. Цикли обробляються пакетами (див. розділ « Що потрібно знати » нижче), розмір яких автоматично підлаштовується під апаратне забезпечення вашого сервера. Скасування поточного циклу призведе до скасування пакетів, які ще не розпочалися; проте поточний пакет продовжуватиме виконуватися, доки не буде завершено.

Перегляд результатів циклу

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.

Post loop logs

Важливі примітки

  1. 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.
  2. 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.

Під капотом

  1. 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.
  2. Оскільки цикли виконуються у фоновому режимі, дії, що не входять до циклу, зазвичай завершуються раніше за сам цикл. Якщо ви хочете, щоб дія в рецепті виконувалася після завершення циклу, єдиний спосіб зробити це – вручну вказати затримку для дії.
  3. Цикли виконуються пакетами . Розмір і частота цих пакетів автоматично адаптуються до можливостей вашого сервера і не можуть бути налаштовані вручну.
  4. Ви можете зупинити цикл, що виконується, з журналів. Однак, пакет, що виконується, не можна зупинити, і він виконуватиметься до завершення. Будь-які пакети, які ще не розпочалися, будуть скасовані.
  5. Скільки часу потрібно для завершення циклу, залежить від багатьох факторів, зокрема:
    • The number of posts the loop iterates over
    • Кількість фільтрів усередині циклу
    • Кількість дій усередині циклу
    • Тип дій усередині циклу (деякі дії повільніші за інші)
    • Можливості сервера, на якому розміщено сайт
На початок сторінки