WP-CLI Get Site ID from its url

It looks like --url isn’t working to filter the wp site list output.

So instead one could try:

wp site list | awk '{ if( $2 == SITE_URL_STRING ) print $1; }'

where we use the awk trick from here, to filter the url column and display the blog_id column.

Here we must replace SITE_URL_STRING with e.g. "https://blog.example.com/site9/".

Update: Here’s a bash example to find the exact site url string:

#!/bin/bash
site_url="https://blog.example.com/site9/"
wp site list | awk -v site_url=$site_url '{ if( $2 == site_url ) print $1; }'

where we use the -v option to pass a shell variable to awk. Got that idea from here.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)