【发布时间】:2017-12-28 13:57:32
【问题描述】:
我相当卡在某事上。我正在尝试通过 JSON 在 WP_User_Query 的 include 参数中放置一个 id 数组。
我的代码如下:
public function get_following_ids( $user_id = 0 ) {
$following = array();
$existing = $wpdb->get_var( $wpdb->prepare( "SELECT following FROM {$this->table} WHERE user_id = %d", absint( $user_id ) ) );
$following = json_decode( $existing );
return ( $following );
}
WP_User_查询码
public function author_following_list( $user_following_ids ) {
$args = array(
...
'include' => json_encode( $user_following_ids )
);
$user_query = new WP_User_Query( $args );
$follow_users = $user_query->get_results();
ob_start();
if ( ! empty( $follow_users ) ) {
foreach ( $user_query->results as $user ) {
...
}
} else {
echo 'no users';
}
$content = ob_get_contents();
ob_end_clean();
echo $content;
}
然后在我使用的另一个函数中:
$following_ids = $this->get_following_ids( $user_to_follow );
$this->author_following_list( $following_ids );
当我在the author_following_list 函数中使用var_dump( $user_following_ids ); 时,它会显示array(2) { [0]=> string(1) "2" [1]=> string(1) "3" }
但我得到'no users' 作为输出。
有人可以让我在解决这个问题上走上正轨吗?
【问题讨论】: