Alfred Workflow – WP Site List

Alfred Workflow – WP Site List

A WordPress Plugin and Alfred Workflow to quickly retrieve a blog_id from a WP Multisite Network

Managing 70+ sites on a WordPress network is a big part of my day. These sites are not left and forgotten about, each site requires attention, maintenance, upgrades, imports, exports, duplication – just lots of moving things around and pin-pointing other things.

One of the biggest headaches I face in my work flow was looking up the blog_id of a site within the network. It’s not a hard or specific task, currently I have four ways to retrieve one:

  1. Ask Slack with a proprietary slash command to look up client in project database
  2. WP Admin Network list of sites in /wp-admin/network/sites.php
  3. WP Admin I’ve added the ID of each site in the footer of each sites /wp-admin/ dashboard
  4. wp-cli‘s wp site list command

However, each of these ways still requires jumping out of what I’m doing, and they all have tiny headaches:

  1. using slack adds bloat to the channels
  2. getting into the WordPress network admin requires lots of clicking
  3. getting into a sites dashboard requires typing the domain and a login
  4. wp-cli site list is huge, and requires resizing terminal window & using cmd+f

Each work – but each has it’s annoyance. What I needed was an Alfred Workflow to find the ID of a site based on a quick keyword, allowing me to retrieve the ID above my current tasks. Unable to find anything, I built a custom Alfred Workflow, with PHP, Bash & Javascript / NodeJS:

The wpsitelist command, followed by a keyword from the path of the site I’m looking for, reveals a list of the sites that contain the keyword. Selecting the site gives my clipboard the ID. Easy as pie. (Sites are asterisk out in demo for client privacy).

To do this, I first had to create a REST endpoint on my WordPress Multisite Network installation. An easy enough task, and broad enough functionality to release it as a simple 60-line PHP plugin. Activating this simple plugins gives my network the following endpoint (plus search filter):


Going to the REST API endpoint gives a JSON object of all sites path, domains, and their blog ID’s. In the plugin I’ve cache’d it for 24 hours, and added a query that does a rudimentary strstr() argument to filter the cache’d results to only what’s looked for.

Next, for Alfred I created a workflow using npm’s got to get the REST data, then alfy to give the results to Alfred.

All told it’ll saves me just little over two dozen seconds a day – if that – and it took several hours to put together. However, as any developer knows, removing headache-tasks like the ID lookup saves so much stress, improves moral, and boosts productivity. As well as scratching your own itches and using different technologies and languages is fun and a good way to keep learning.

Well worth it.

%d bloggers like this: