0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

[wp-cli] 予約投稿が失敗したときにリカバリさせるためのシェルスクリプト

Posted at

こんな感じのスクリプトをサーバの cron で毎分実行すれば、きっと大丈夫
post_statusfuture で、投稿日時が1時間前〜現在までの投稿があったら、wp_publish_post() を実行して投稿処理を実施します。

#!/bin/bash
WP_ROOT=${1:-/var/www/html}
WPCLI="wp --path=${WP_ROOT}"
table_prefix=$(${WPCLI} eval 'global $table_prefix; echo $table_prefix;')
post_ids=$(${WPCLI} db query "select ID from ${table_prefix}posts where post_status = 'future' and post_date BETWEEN (NOW() - INTERVAL - 1 hour) AND NOW() order by post_date_gmt;" | awk '{print $1}' | grep -v 'ID')
for post_id in ${post_ids}; do
    echo ${post_id}
    ${WPCLI} eval "wp_publish_post(${post_id});"
done
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?