Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/247.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
Php WordPress高级自定义字段转发器字段--get_字段不适用于我_Php_Wordpress_Repeater_Custom Fields - Fatal编程技术网

Php WordPress高级自定义字段转发器字段--get_字段不适用于我

Php WordPress高级自定义字段转发器字段--get_字段不适用于我,php,wordpress,repeater,custom-fields,Php,Wordpress,Repeater,Custom Fields,这里是准noob。我只是无法从get_字段中得到任何结果。这是我的测试页面: http://23.21.199.240/test 我可以使用FOR循环检索转发器字段数据,但是特殊的ACF get_字段函数没有达到我的预期效果。(这看起来很简单,所以如果我犯了一个彻头彻尾的错误,我不会感到惊讶。) 任何帮助都将不胜感激 <?php /* Template Name: test */ ?> <?php get_header(); ?> <?php quer

这里是准noob。我只是无法从get_字段中得到任何结果。这是我的测试页面:

    http://23.21.199.240/test
我可以使用FOR循环检索转发器字段数据,但是特殊的ACF get_字段函数没有达到我的预期效果。(这看起来很简单,所以如果我犯了一个彻头彻尾的错误,我不会感到惊讶。)

任何帮助都将不胜感激

<?php
/*
Template Name: test
*/
?>

<?php get_header(); ?>

<?php query_posts('category_name=worldwise&posts_per_page=3'); ?>

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

    id: <?php the_ID(); ?><br />

    <!--let's try to display all the topics (an ACF repeater field) for this post....-->

    <?php if(get_field('topic')): // if there are topics, get all their data in an array ?>

        <?php
            $topic_list_1 = ''; // set up an empty topic list
            while(has_sub_field('topic')): // for every topic 
                $topic_title_1 = get_sub_field('topic_title'); // get the title
                $topic_list_1 .= '<li>' . $topic_title_1 . '</li>'; // and add it to the topic list
            endwhile;  // no more topics, move on
        ?>

        <p><strong>The FOR loop produced these topics:</strong></p>
        <ul><?php echo $topic_list_1; ?></ul>

    <?php else: ?>

        <p style="color:red">GET_FIELD did not find any topics</p>

    <?php endif; ?>

    <!--or, let's try displaying those topics another way....-->

    <?php
        $vid_id = $post->ID;
        $vid_custom = get_post_custom($vid_id);
    ?>

    <?php if($vid_custom['topic'][0] != null): ?>

        <?php
            $topic_list_2 = '';
            for($r=0;$r<$vid_custom['topic'][0];$r++):
                $topic_title_2 = $vid_custom[topic_.$r._topic_title][0];
                $topic_list_2 .= '<li>' . $topic_title_2 . '</li>';                 
            endfor;
        ?>

        <p><strong>The FOR loop produced these topics:</strong></p>
        <ul><?php echo $topic_list_2; ?></ul>

    <?php else: ?>

        <p style="color:red">The FOR loop did not find any topics</p>

    <?php endif; ?>

    <br />

<?php endwhile; else: ?>

    <p>Sorry, no posts or pages matched your criteria.</p>

<?php endif; ?>

id:
FOR循环产生了以下主题:

    获取字段未找到任何主题

    FOR循环产生了以下主题:

      FOR循环未找到任何主题


      抱歉,没有与您的条件匹配的帖子或页面


      我不喜欢使用get\u sub\u field方法,因为嵌套中继器字段时会变得有点复杂

      在我看来,这是获得你想要做的事情的最简单方法:

      <ul>
      <?php foreach (get_field('topic') as $row) :?>
          <li><?php print $row['topic_title'] ?></li>                  
      <?php endforeach; ?>
      </ul>