-
-
Save celian-m/dbff452ab80f081d4ccf0c032aec66ee to your computer and use it in GitHub Desktop.
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment