Skip to content

Commit 7c87da7

Browse files
committed
feat(media): adds script for searching media library by post title
1 parent 1ea46c9 commit 7c87da7

1 file changed

Lines changed: 2 additions & 8 deletions

File tree

search-posts-media-library.sh

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,6 @@ for site_id in $all_site_ids; do
2727
continue;
2828
fi
2929

30-
echo >> $output_file;
31-
echo "Results for Site ID ${site_id}" >> $output_file;
32-
33-
# Search for multi term phrases. Cases sensitive.
34-
wp_skip_all db query --skip-column-names "SELECT ${fields} FROM wp_${site_id}_posts WHERE post_type = 'attachment' AND post_REGEXP '${search_regex}';" >> $output_file;
35-
3630
# The SQL query for searching the media library of a network site.
3731
sql_query="SELECT
3832
$site_id as site_id,
@@ -50,10 +44,10 @@ for site_id in $all_site_ids; do
5044

5145
# Check if a search string was provided.
5246
if [ -n "$search_regex" ]; then
53-
QUERY="$QUERY AND p.post_title REGEXP '${search_regex}'"
47+
sql_query="$sql_query AND p.post_title REGEXP '${search_regex}'"
5448
fi
5549

56-
wp_skip_all db query --skip-column-names "SELECT ${fields} FROM wp_${site_id}_posts WHERE post_type = 'attachment' AND post_REGEXP '${search_regex}';" tee -a $output_file;
50+
wp_skip_all db query --skip-column-names "$sql_query" | tee -a $output_file;
5751

5852
done;
5953

0 commit comments

Comments
 (0)