Skip to content

Commit 207817b

Browse files
committed
feat(media): add search of media library, output as csv
1 parent 7c87da7 commit 207817b

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

search-posts-media-library.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ for site_id in $all_site_ids; do
3838
FROM
3939
wp_${site_id}_posts p
4040
LEFT JOIN
41-
wp_3_postmeta pm1 ON (p.ID = pm1.post_id AND pm1.meta_key = '_wp_attached_file')
41+
wp_${site_id}_postmeta pm1 ON (p.ID = pm1.post_id AND pm1.meta_key = '_wp_attached_file')
4242
WHERE
4343
p.post_type = 'attachment'"
4444

@@ -47,7 +47,8 @@ for site_id in $all_site_ids; do
4747
sql_query="$sql_query AND p.post_title REGEXP '${search_regex}'"
4848
fi
4949

50-
wp_skip_all db query --skip-column-names "$sql_query" | tee -a $output_file;
50+
# Run the wpcli command | use sed to replace tabs with commas | output to shell and file.
51+
wp_skip_all db query --skip-column-names "$sql_query" | sed -E 's/"/""/g; s/\t/","/g; s/^/"/; s/$/"/' | tee -a $output_file;
5152

5253
done;
5354

0 commit comments

Comments
 (0)