Wordpress 如何将中继器子字段转换为标记
我有一个循环,它通过中继器以天('d')的格式输出日期和时间子字段的不同值。我想知道如何将$dia的每个不同值转换为一个标记,以防它有多个值(问题是,到目前为止,我所做的只是输出$dia的最后一个值) 这就是我到目前为止所做的:Wordpress 如何将中继器子字段转换为标记,wordpress,loops,tags,repeater,Wordpress,Loops,Tags,Repeater,我有一个循环,它通过中继器以天('d')的格式输出日期和时间子字段的不同值。我想知道如何将$dia的每个不同值转换为一个标记,以防它有多个值(问题是,到目前为止,我所做的只是输出$dia的最后一个值) 这就是我到目前为止所做的: if( have_rows('quando', $post_id) ): while( have_rows('quando', $post_id) ): the_row(); $dataCrua = get_sub_field('dia_e_hora', $
if( have_rows('quando', $post_id) ):
while( have_rows('quando', $post_id) ): the_row();
$dataCrua = get_sub_field('dia_e_hora', $post_id);
$data = DateTime::createFromFormat("Y-m-d H:i:s", $dataCrua);
if ( is_object($data) ) {
$dia = $data->format('d');
}
$tags = $dia;
wp_set_post_tags( $post_id, $tags);
endwhile;
endif;
?>
如果'dia_e_hora'是中继器,$dataCrua是一个数组。你必须用foreach循环通过它 我想这应该管用
<?php
if( have_rows('quando', $post_id) ):
while( have_rows('quando', $post_id) ): the_row();
$dataCrua = get_sub_field('dia_e_hora', $post_id);
$dia = array();
foreach($dataCrua as $data_entry) {
$data = DateTime::createFromFormat("Y-m-d H:i:s", $data_entry);
if ( is_object($data) ) {
$dia[] = $data->format('d');
}
}
$tags = $dia;
wp_set_post_tags($post_id, $tags);
endwhile;
endif;
?>
如果'dia_e_hora'是中继器,$dataCrua是一个数组。你必须用foreach循环通过它 我想这应该管用
<?php
if( have_rows('quando', $post_id) ):
while( have_rows('quando', $post_id) ): the_row();
$dataCrua = get_sub_field('dia_e_hora', $post_id);
$dia = array();
foreach($dataCrua as $data_entry) {
$data = DateTime::createFromFormat("Y-m-d H:i:s", $data_entry);
if ( is_object($data) ) {
$dia[] = $data->format('d');
}
}
$tags = $dia;
wp_set_post_tags($post_id, $tags);
endwhile;
endif;
?>
解决了它
$tags = array();
if( have_rows('quando', $post_id) ):
while( have_rows('quando', $post_id) ): the_row();
$dataCrua = get_sub_field('dia_e_hora', $post_id);
$data = DateTime::createFromFormat("Y-m-d H:i:s", $dataCrua);
if ( is_object($data) ) {
$dia = $data->format('d');
}
$tags[] = $dia;
wp_set_post_tags( $post_id, $tags, false);
endwhile;
endif;
?>
解决了
$tags = array();
if( have_rows('quando', $post_id) ):
while( have_rows('quando', $post_id) ): the_row();
$dataCrua = get_sub_field('dia_e_hora', $post_id);
$data = DateTime::createFromFormat("Y-m-d H:i:s", $dataCrua);
if ( is_object($data) ) {
$dia = $data->format('d');
}
$tags[] = $dia;
wp_set_post_tags( $post_id, $tags, false);
endwhile;
endif;
?>