Wordpress 循环自定义帖子类型作为wp alchemy中的复选框
我在Wordpress上遇到了点麻烦。我正在使用wpalchemy将自定义元字段添加到我的帖子类型中。我有一个岗位类型的员工和一个岗位类型的客户。我想在客户元框中列出所有员工的复选框,以便管理员可以显示哪些员工与每个客户一起工作。到目前为止,我掌握的代码如下:Wordpress 循环自定义帖子类型作为wp alchemy中的复选框,wordpress,Wordpress,我在Wordpress上遇到了点麻烦。我正在使用wpalchemy将自定义元字段添加到我的帖子类型中。我有一个岗位类型的员工和一个岗位类型的客户。我想在客户元框中列出所有员工的复选框,以便管理员可以显示哪些员工与每个客户一起工作。到目前为止,我掌握的代码如下: <?php $type = 'medewerkers'; $args = array( 'post_type' => $type, 'post_
<?php
$type = 'medewerkers';
$args = array(
'post_type' => $type,
'post_status' => 'publish',
'posts_per_page' => -1,
'caller_get_posts'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
$metabox->the_group_open();
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<?php
$meta = get_post_meta(get_the_ID());
$naam = $meta['voornaam'][0].' '.$meta['achternaam'][0];
?>
<br/><?php $metabox->the_field($naam); ?>
<img src="<?php echo $meta['pasfoto'][0]; ?>" height="40" width="40" style="vertical-align: middle">
<input type="checkbox" name="<?php $metabox->the_name(); ?>" value="1"<?php if ($metabox->get_the_value()) echo ' checked="checked"'; ?>/> <?php echo $naam; ?>
<?php
endwhile;
$metabox->the_group_close();
}
?>
“height=“40”width=“40”style=“垂直对齐:中间”>
/>
它可以工作,但我不满意。员工作为单独的项目而不是数组存储。我希望能够循环,例如,通过前端的数组显示与当前客户端关联的所有员工
非常感谢您的帮助。我已经设法解决了它:
<?php
$type = 'medewerkers';
$args = array(
'post_type' => $type,
'post_status' => 'publish',
'posts_per_page' => -1,
'caller_get_posts'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while($mb->have_fields_and_multi('medewerkers')):
$mb->the_group_open();
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<?php
$meta = get_post_meta(get_the_ID());
$naam = $meta['voornaam'][0].' '.$meta['achternaam'][0];
?>
<?php $metabox->the_field($naam); ?>
<img src="<?php echo $meta['pasfoto'][0]; ?>" height="40" width="40" style="vertical-align: middle">
<input type="checkbox" name="<?php $metabox->the_name(); ?>" value="1"<?php if ($metabox->get_the_value()) echo ' checked="checked"'; ?>/> <?php echo $naam; ?>
<?php
endwhile;
$mb->the_group_close();
endwhile;
}
?>
“height=“40”width=“40”style=“垂直对齐:中间”>
/>