获取我的以下用户正在关注的用户

时间:2017-12-26 作者:Michel

我有一个社交网站,其中包含跟踪用户系统。

每个用户有两个自定义元:

following\\u用户我的问题是如何获得我的following用户正在跟踪的用户?

我尝试过这样的方法,但不起作用:

$get_the_following_users = get_user_meta($current_user->ID, \'following_users\', true);
foreach ( $get_the_following_users as $following_user ) {
    $following_user = get_user_meta($following_user, \'following_users\', true);

    $meta_qssuery .= $following_user.\', \';
}

echo $meta_qssuery;
注意:我存储以下\\u用户和followers\\u用户的数组元,如下所示:

a:8:{i:9;i:9;i:57;i:57;i:3;i:3;i:71;i:71;i:85;i:85;i:89;i:89;i:152;i:152;i:2;i:2;}

1 个回复
最合适的回答,由SO网友:inarilo 整理而成

您可以使用implode 连接数组元素的函数:

$get_the_following_users = get_user_meta($current_user->ID, \'following_users\', true);
$meta_qssuery = \'\'; //initialise to an empty string
foreach ( $get_the_following_users as $following_user ) {
    $following_user = get_user_meta($following_user, \'following_users\', true);

    if(!empty($following_user)) { //check if any data was returned
        $meta_qssuery .= implode(\', \', $following_user).\', \';
    }
}

echo $meta_qssuery;
这将在字符串的末尾留下一个额外的“,”。可以在循环结束后删除,也可以修改循环:

$get_the_following_users = get_user_meta($current_user->ID, \'following_users\', true);
$get_the_following_users_2 = array();
foreach ( $get_the_following_users as $following_user ) {
    $following_user = get_user_meta($following_user, \'following_users\', true);

    if(!empty($following_user)) { //check if any data was returned
        $get_the_following_users_2[] = implode(\', \', $following_user);
    }
}

$meta_qssuery = implode(\', \', $get_the_following_users_2);
echo $meta_qssuery;

结束

相关推荐

ARRAY_FILTER WARNING-wp-Includes/post.php第3148行

我插入the following code, 请参见下文,从前端提交帖子。提交时,会出现以下警告:警告:array\\u filter()要求参数1为数组,字符串在[…]中给出/wp包括/后。php在线3148我不知道警告来自哪里,哪个数组是字符串?function ty_front_end_form() { ?> <form id=\"custom-post-type\" name=\"custom-post-type\" method=\"post