users;"); You can ...">

How to query mysql `$ wpdb-> get_var`` bp_groups` in buddypress?

I know that:

$wpdb->get_var("SELECT COUNT(*) FROM $wpdb->users;");

You can select a Wordpress user using mysql, but when I call the buddypress group, it doesn’t work, returns nothing

$wpdb->get_var("SELECT COUNT(*) FROM $wpdb->bp_groups;");

How to fix it?

+4
source share
1 answer

$ wpdb stores information only in Wordpress tables. Buddypress will be in a different place.

The next page has a database map with default table names. Since the "wp_" part is undefined, you will want to use $wpdb->prefix

http://api.buddypress.org/development/legacy-analysis/data-model-1-dot-3/

Therefore, any of the following should work fine.

 $table = $wpdb->prefix."bp_groups"; $wpdb->get_var("SELECT COUNT(*) FROM $table;"); 

or inline

 $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->prefix}bp_groups;"); 

You can use this schematic map as a guide for more information, for example, how many users are in certain groups, etc.

Good luck :)

+4
source

Source: https://habr.com/ru/post/1336880/


All Articles