Support

Account

Home Forums General Issues Querying Posts by User Field Type Reply To: Querying Posts by User Field Type

  • I did it from within the loop so, while not totally straightforward, allowed me to use get_field('participants'), and then foreach( $participants as $participant ) to access each user/participant associated with a given post as an array. From there I could get the user details.

    However, this is not going to work outside of the loop. You could try http://codex.wordpress.org/Class_Reference/wpdb to get specific meta_key values

    I think the following would return an array of all users (where the meta_key is ‘participants’). As users information is itself stored as an serialized array, you’d then need to dig into this.

    $metakey = 'participants';
    $participants = $wpdb->get_col($wpdb->prepare("SELECT DISTINCT meta_value FROM $wpdb->postmeta WHERE meta_key = %s ORDER BY meta_value ASC", $metakey) );

    I’m pretty new to PHP so don’t bet your house on anything here, although I’ve successfully tried all the above. Best of luck