Skip to content

Instantly share code, notes, and snippets.

View celian-m's full-sized avatar

celian celian-m

  • MyStudioFactory
  • Paris
View GitHub Profile
@celian-m
celian-m / index.sh
Created July 24, 2024 17:22 — forked from michael-sumner/index.sh
WP-CLI command to loop through all sites in the multisite network and use wp db query to obtain a list of posts, and save them in log.txt file
# replace "Hello, World!" with appropriate string to search for
# replace `post_title` with appropriate column to search for
wp site list --fields=url,blog_id | while IFS= read -r line; do
url=$(echo "$line" | awk -F'\t' '{print $1}')
blog_id=$(echo "$line" | awk -F'\t' '{print $2}')
wp post list --field=url --ignore_sticky_posts=1 --orderby=date --order=DESC --post__in=$(wp db query "SELECT ID FROM wp_${blog_id}_posts WHERE post_title LIKE '%Hello, World!%' AND post_status='publish' AND post_type='post'" --skip-column-names --url=${url} | paste -s -d ',' -) --url=${url}
done >> log.txt