Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress 如何将中继器子字段转换为标记_Wordpress_Loops_Tags_Repeater - Fatal编程技术网

Wordpress 如何将中继器子字段转换为标记

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', $

我有一个循环,它通过中继器以天('d')的格式输出日期和时间子字段的不同值。我想知道如何将$dia的每个不同值转换为一个标记,以防它有多个值(问题是,到目前为止,我所做的只是输出$dia的最后一个值)

这就是我到目前为止所做的:


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;
     ?>