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 3 years have passed since last update.

[WordPress] 特定の文言が含まれる投稿のリストを作成したい

Posted at

WordPress で特定の文言が含まれる投稿のリストを作成したい時ってありますよね。
wp-cli を使って、こんな感じのシェルスクリプトを作ってやれば、なんとなく CSV ができます。

#!/bin/bash
KEYWORD="${1:-ハナクソ}"
TABLE=$(wp eval 'global $wpdb;echo $wpdb->posts;')
POSTS=$(wp db search "${KEYWORD}" ${TABLE} --one_line --table_column_once | grep ${TABLE} | awk -F ':' '{print $3}' | sort | uniq)
echo "ID,post_date,post_title,permalink,post_type,post_status"
for POST in ${POSTS} ; do
  wp eval "\$post=get_post(${POST}); if (\$post->post_status !== 'inherit') { echo \$post->ID.','.\$post->post_date.','.\$post->post_title.','.get_permalink(${POST}).','.\$post->post_type.','.\$post->post_status.\"\\n\"; }"
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?