如何 运行 循环从 wordpress 中的多个复选框中获取数据?

How to run a loop to fetch a data from multi chekboxes in wordpress?

我正在尝试从复选框中获取数据,但出现错误:

"Array to string conversion in C:\xampp\htdocs\blogger\wp-content\themes\blogger\single-book.php on line 16"

我试过这段代码:

function.php

    $books->add_field(array(
            'id'         => 'select',
            'name'       => 'This is a checkboxes',
       //   'desc'       => 'How to Train Your Dragon Story',
            'type'    => 'multicheck',
            'options' => array(
            'check1' => 'Check One',
            'check2' => 'Check Two',
            'check3' => 'Check Three',
        ),

        ));

index.php

     <?php echo get_post_meta(get_the_id(),'select',true);

您似乎在使用 CMB2 插件,您的代码
<?php echo get_post_meta(get_the_id(),'select',true); ?>
将 return 一个包含值的数组。只有选中的值才会出现。在您的代码中 get_the_ID() 被错误地称为 id 应该在 capital 中。

    $vals= get_post_meta(get_the_ID(),'select',true); 
    foreach ($vals as $key => $v) {
        echo $v;
    }

希望这对你有用,