the_author_meta() wont show inline text in { }

144
December 12, 2018, at 00:30 AM

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.

Answer 1

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>";
}
?>
Rent Charter Buses Company
READ ALSO
Insert problem in the Database with foreign key using pdo

Insert problem in the Database with foreign key using pdo

in fact my problem is that am not able to save data in the table educationThe table education has a foreign key (applicantID) which is the primary key in the table applicant

91
php: regex - word between two words [duplicate]

php: regex - word between two words [duplicate]

This question already has an answer here:

149
Como crear select en PhpGrid con una Query? [on hold]

Como crear select en PhpGrid con una Query? [on hold]

Estoy intentando crear web con el framework PHPGrid, y necesito que las options del select sean de una query [select u_id, name from profesores] donde además se quede seleccionado mi nombre si el u_id es igual al de session

117