0

Hello I have a social network site and I want to make (Who to follow) widget like Twitter, each user I have on my site have two custom meta:

  • following_users (users that I follow)
  • followers_users (users that follow me)

it's save into database like this: a:1:{i:0;s:1:"1";}

Now I need to get the users that my following users are following like Twitter by using WP_User_Query.

I just can't make the trick, in my opinion, i need to make foreach inside foreach but sure it's not logic.

  • You can't search for serialised PHP structures, nor should you search for things via their meta, that's what taxonomies for. Are you aware you can have multiple post meta with the same name? – Tom J Nowell Nov 19 '17 at 1:20
0

It looks like you're saving a PHP std object in the database. It might be an array, I'd have to check how WordPress saves those. In either case:

If you're using add_user_meta() or update_user_meta() to insert the user meta into the database (and you should be), then using get_user_meta() with the third parameter set to true should return a single object/array that is identical to the one that you inserted into the database.

$following_users = (object) [ '1' ]; /* or just the array */

update_user_meta( $user_id, 'my_user_meta_key', $following_users );

$users = get_user_meta( $user_id, 'my_user_meta_key', true );

$users and $following_users should be identical. So get the user IDs however you saved them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.