2

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!

1 Answer 1

2
$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
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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