1

I am working on creating a function that will take a $blog_id and return the corresponding $user_id of the user who owns/created the blog in a multi site network.

public function SelectOwnerUserIdFromBlogId( $blog_id ) { ... }

I have been reviewing the database and the closest thing I can find is looking at the wp_usermeta table and filtering on capabilities but this feels too hackish. Any better idea?

SELECT user_id as UserId,
    IF(SUBSTRING_INDEX(SUBSTRING_INDEX(meta_key, '_', 2), '_', -1) = 'capabilities', 1, SUBSTRING_INDEX(SUBSTRING_INDEX(meta_key, '_', 2), '_', -1)) as BlogId
FROM wp_usermeta
WHERE meta_key like '%_capabilities'
    AND meta_value like '%administrator%'

Query results.

1 Answer 1

2

I know this is old, but this is the best way. Might help people coming here in the future.

$get_users = get_users( array( 'blog_id' => get_current_blog_id() ) ); $user_id = $get_users[0]->ID;

1
  • why would you name an array variable that looks like a function? Mar 31, 2020 at 12:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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