【发布时间】:2018-02-22 20:44:01
【问题描述】:
我正在尝试查询在转发器字段中选中了特定复选框的所有帖子。
我找到了这个tutorial,我想做的是主题 3 和 4 的混合,但我自己无法完成,我的第一次尝试是查询所有帖子并只打印一个选中的项目:
<?php
$args = array(
'post_type' => 'modalidade',
'posts_per_page' => -1,
);
$loop = new WP_Query( $args );
?>
<?php
// check if the repeater field has rows of data
if( have_rows('horarios') ):
// loop through the rows of data
while ( have_rows('horarios') ) : the_row();
$dia_da_semana = get_sub_field_object( 'dia_da_semana' );
$horario = get_sub_field_object( 'horario' );
if ( in_array(1, $dia_da_semana['value'])) {
echo 'segunda';
print_r( $horario['value']);
echo '<br>';
}
endwhile;
endif;
?>
但不要认为这是一个好的解决方案。也许有更好的方法来实现我想要做的事情。
【问题讨论】:
-
请更新您的问题,将您的相关代码包含在Minimal, Complete, and Verifiable example 中,并详细说明您迄今为止尝试过的内容以及为什么它不起作用。
-
完成!感谢提醒!
-
你的 WP 查询在哪里?
-
我只是在查询一个CTP的所有帖子,我现在在问题中添加了。
标签: mysql wordpress advanced-custom-fields