PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, July 3, 2022

[FIXED] How to get users who belong to a WordPress Multisite blog (site) with SQL?

 July 03, 2022     multisite, sql, wordpress     No comments   

Issue

I need to get all the users who have joined (are members) of a site (blog) in WordPress multisite. To complicate it, I am doing this outside of WordPress and don't have access to internal Wordpress functions, so need to construct the SQL directly.

In English the SQL would break down as "get an array of user IDs of users that are members of site x" (where site relates to one of the WordPress Multisite sites).

I've tried going through WordPress code to understand, but struggling with the above.

I don't need the PHP, I can work that out, just an example SQL statement.

Many thanks!


Solution

  1. select * from wp_blogs

From the output of the command note down the blog_id you want the users of. For eg: say you are wanting the users of the site with blog_id = 2 , next run the following query.

  1. select * from wp_users u join wp_usermeta um on u.id=um.user_id where um.meta_key="wp_2_capabilities"


Answered By - Anand Shah
Answer Checked By - Candace Johnson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing