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
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.