Question

I have a post_meta "thevoters" that store users ids like: 1,2,20 ...etc, How i can turn this id's to User Names to list them in a single page?

This will echo the numbers as text,

echo get_post_meta(get_the_ID(), "thevoters", true);

any help?
thanks a lot!

Was it helpful?

Solution

$thevoters_ids = get_post_meta( get_the_ID(), "thevoters", true ); // get a comma separated list of ids

$thevoters_ids = explode( ',', $thevoters_ids ); // turn the list into an array

foreach ( $thevoters_ids as $thevoter_id ) { // loop through the ids
    $thevoter = get_user_by( 'id', $thevoter_id ); // get the user object by id
    echo $thevoter->display_name; // display the user name
}
Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top