I know I can get a site list with wp site list –path=”$pathtowordpress”

What I want to do though is get one site’s ID by knowing only it’s url.

Does anyone know if this is possible ?

Tnaks.

1 Answer
1

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.

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *