I need to search through dozens of WordPress multisite (network enabled) installs for sites that use a particular plugin.

How can I list only sites that use a particular theme or plugin, preferably with either WP CLI or a database query?

1 Answer 1


WP CLI is the easiest option here.

First, we want an array/list we can store the desired sites in:


Then, we get a list of all sites as a variable, and loop over them:

blogs=$(wp site list --fields="blog_id" --format="csv")
for entry in $blogs
    if [ "${entry}" == "blog_id" ]; then
        continue # skip the CSV header

Next, grab the sites active theme:

    theme=$(wp theme list --status=active --format=csv --fields="name" --url="${entry}" | sed -n 2p)

Here I'm using | sed -n 2p to get the second line of output in order to skip the CSV header.

Then, if the sites theme matches what we're looking for, add it to a list:

    if $theme == 'mytheme';
    if [ "${theme}" == "mytheme" ]; then

Then we close our loop


Turn our list into a comma separated string, and pass it to wp site list via --sites__in:

wp site list --site__in="${results[*]}"

We could also swap the retrieval of the theme and the check for a wp plugin is-active call if we wanted to filter by active plugin, e.g. wp plugin is-active hello


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.