Created
August 6, 2020 16:32
-
-
Save trepmal/1391abac6766ac2baf4be30676966e47 to your computer and use it in GitHub Desktop.
This file contains 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
#!/bin/bash | |
echo "post_id,post_title,image_path"; | |
while read -r post_row | |
do | |
# --format=csv always has a header | |
if [[ "ID,post_title" == $post_row ]]; then | |
continue; | |
fi; | |
post_id=${post_row%,*} | |
post_title=${post_row#*,} | |
echo -n $post_row','; | |
thumbid=$(wp post meta get $post_id _thumbnail_id) | |
if [ ! -z $thumbid ]; then | |
wp post meta pluck $thumbid _wp_attachment_metadata file | |
else | |
echo ''; | |
fi; | |
done < <(wp --skip-plugins --skip-themes post list --post_type=page --fields=ID,post_title --format=csv) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This uses a while loop because of the post titles being fetched... spaces throw off a for loop.