dpca4790 2018-12-10 21:20
浏览 55
已采纳

the_author_meta()不会在{}中显示内联文字

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.

  • 写回答

1条回答 默认 最新

  • douqian2957 2018-12-10 22:20
    关注

    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>";
    }
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
  • ¥15 onvif+openssl,vs2022编译openssl64