使用 wpdb > 获取与分类相关的用户列表

using wpdb > get a list of users that are associated with taxonomy

我想获取与 taxonomy_id = 1186

关联的用户 ID 列表

我从以下 wpdb 函数得到了结果(由于某些原因我需要使用 wpdb)

$result = $wpdb->get_results( "SELECT u.ID FROM wp_users u INNER JOIN wp_term_relationships r ON u.ID = r.object_id WHERE u.user_status = 0 AND r.term_taxonomy_id = 1186");

但我得到的结果是这样显示的 https://snipboard.io/otBFli.jpg

Array ( [0] => stdClass Object ( [ID] => 27 ) [1] => stdClass Object ( [ID] => 50 ) [2] => stdClass Object ( [ID] => 148 ) [3] => stdClass Object ( [ID] => 160 ) [4] => stdClass Object ( [ID] => 212 ) [5] => stdClass Object ( [ID] => 234 ) [6] => stdClass Object ( [ID] => 263 ) [7] => stdClass Object ( [ID] => 308 ) [8] => stdClass Object ( [ID] => 352 ) [9] => stdClass Object ( [ID] => 400 ) [10] => stdClass Object ( [ID] => 433 ) [11] => stdClass Object ( [ID] => 449 ) [12] => stdClass Object ( [ID] => 465 ) [13] => stdClass Object ( [ID] => 588 ) [14] => stdClass Object ( [ID] => 604 ) [15] => stdClass Object ( [ID] => 674 ) [16] => stdClass Object ( [ID] => 677 ) [17] => stdClass Object ( [ID] => 759 ) [18] => stdClass Object ( [ID] => 949 ) [19] => stdClass Object ( [ID] => 1143 ) [20] => stdClass Object ( [ID] => 1166 ) [21] => stdClass Object ( [ID] => 1178 ) [22] => stdClass Object ( [ID] => 1180 ) [23] => stdClass Object ( [ID] => 1565 ) [24] => stdClass Object ( [ID] => 1590 ) [25] => stdClass Object ( [ID] => 1786 ) [26] => stdClass Object ( [ID] => 1992 ) [27] => stdClass Object ( [ID] => 2133 ) [28] => stdClass Object ( [ID] => 2312 ) [29] => stdClass Object ( [ID] => 2380 ) [30] => stdClass Object ( [ID] => 3250 ) [31] => stdClass Object ( [ID] => 3678 ) [32] => stdClass Object ( [ID] => 4909 ) [33] => stdClass Object ( [ID] => 5766 ) [34] => stdClass Object ( [ID] => 5767 ) [35] => stdClass Object ( [ID] => 5824 ) [36] => stdClass Object ( [ID] => 6076 ) [37] => stdClass Object ( [ID] => 6461 ) [38] => stdClass Object ( [ID] => 6660 ) [39] => stdClass Object ( [ID] => 6702 ) [40] => stdClass Object ( [ID] => 6723 ) [41] => stdClass Object ( [ID] => 6829 ) [42] => stdClass Object ( [ID] => 6877 ) [43] => stdClass Object ( [ID] => 7112 ) ) Array ( [0] => stdClass Object ( [ID] => 5766 ) )

但我想将此结果以下列方式回应 27,50,148,160,212,234.....5766

我该如何实现?

谢谢!

试试下面的代码。

$all_ids = array();

$result = $wpdb->get_results( "SELECT u.ID FROM wp_users u INNER JOIN wp_term_relationships r ON u.ID = r.object_id WHERE u.user_status = 0 AND r.term_taxonomy_id = 1186", ARRAY_A );

foreach ( $result as $key => $id ) {
    $all_ids[] = $id['ID'];
}

if( !empty( $all_ids ) ){
    echo implode( ',', $all_ids );
}