• trying to solve a simple problem, I think.

    in table wp_ / wp_usermeta

    I have the following fields and info.

    Assume I am on a page, user is logged in, I wish to show this user who else has marked a post for “watching”. I use wp-favourites plugin to allow user to watch a post (or item, in my case).

    info:

    umeta_id 27711
    user_id 2
    meta_key wpfp_favorites
    meta_value a:3:{i:0;s:6:”342081″;i:1;s:6:”342073″;i:2;s:6:”342067″;}
    the number ‘342073’ is a $post_ID, for example.

    how do I get get every user_id where meta_value contains $post_ID as array.
    then resolve array into user_ID as nice name,

    wish to return list of users as comma seperated text.
    such as “jeff, john, and Bill” are watching this post.

Viewing 1 replies (of 1 total)
  • Thread Starter vincej

    (@vincej)

    got it. this seems to work.

    Echo "Current MEMBERS watching items  <p> " ;
    global $wpdb ;
    $querystr = "
        SELECT user_id
    FROM <code>wp_usermeta</code>
    WHERE <code>meta_key</code> LIKE '%wpfp%'
    LIMIT 0 , 30
     " ;
    
    $x = $wpdb->get_results($querystr , OBJECT)   ;
     foreach ($x as  $r) {
    $user_info = get_userdata($r->user_id);
          echo '<strong>' . $user_info->user_login . '</strong> User ID: ' . $user_info->ID . "\n";
      }
Viewing 1 replies (of 1 total)
  • The topic ‘simple query, I thought… get users from wp_usermeta’ is closed to new replies.