In the array I have two users, and foreach user the meta variables holds 30,20,40 and 10,5,15.
Why are the variables not displayed inline?
My code:
<?php
$blogusers = get_users( 'blog_id=1&orderby=nicename&role=subscriber' );
foreach ( $blogusers as $user ) {
$boern = the_author_meta('boern',$user->ID);
$voksne = the_author_meta('voksne',$user->ID);
$vegetarer = the_author_meta('vegetarer',$user->ID);
echo "<p> {$user->display_name} har tilmeldt {$voksne} voksne, {$boern} børn og {$vegetarer} vegetarer. </p>";
}
?>
Output:
302040
John har tilmeldt voksne, børn og vegetarer.
10515
Hans har tilmeldt voksne, børn og vegetarer.
If instead I say:
$boern = 1;
$voksne = 2;
$vegetarer = 3;
It works just fine.
According to your output, the meta data is printed first because the_author_meta()
echo's the value, to get or assign the value to a variable you should use get_the_author_meta()
function. Here is the updated code, I think this fixes your issue
<?php
$blogusers = get_users( 'blog_id=1&orderby=nicename&role=subscriber' );
foreach ( $blogusers as $user ) {
$boern = get_the_author_meta('boern',$user->ID);
$voksne = get_the_author_meta('voksne',$user->ID);
$vegetarer = get_the_author_meta('vegetarer',$user->ID);
echo "<p> {$user->display_name} har tilmeldt {$voksne} voksne, {$boern} børn og {$vegetarer} vegetarer. </p>";
}
?>