Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.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
Ajax Foreach循环通过cpt类别使用ACF值_Ajax_Wordpress_If Statement_Foreach_Advanced Custom Fields - Fatal编程技术网

Ajax Foreach循环通过cpt类别使用ACF值

Ajax Foreach循环通过cpt类别使用ACF值,ajax,wordpress,if-statement,foreach,advanced-custom-fields,Ajax,Wordpress,If Statement,Foreach,Advanced Custom Fields,我正在循环我的CPT类别,我想在我的for each循环中使用我的ACF字段 <div id="response"> <?php $args = array( 'post_type' => 'segments-overview', 'orderby' => 'date', // we will sort posts by date 'posts

我正在循环我的CPT类别,我想在我的for each循环中使用我的ACF字段

 <div id="response">
         <?php
         $args = array(
          'post_type'  => 'segments-overview',
           'orderby' => 'date', // we will sort posts by date
           'posts_per_page' => -1
        );



        $query = new WP_Query( $args );
        $all_terms = [];
        if( $query->have_posts() ) :
          while( $query->have_posts() ): $query->the_post();

          $terms = get_the_terms(get_the_ID(), 'category-segments-overview');
          foreach($terms as $term) $all_terms[$term->term_id] = $term;

          endwhile;

          foreach($terms as $term):
            ?>

          <div class="segments-card">
            <div class="img">image</div>
            <div class="content">
                <div class="title"><?php echo $term->name; ?></div>
                
                // ACF field
                <?php echo the_field('product', $term->taxonomy) ; ?>

                <a class="button transparent" href="/segments/<?php echo $term->slug; ?>">
                <?php echo __('View All','axia'); ?>
              </a>
            </div>
            </div>
          </div>

        <?php endforeach;

          wp_reset_postdata();
        else :
          ?>
          <div class="no-posts-found">
            <h2>There were no items found</h2>
              <h3>Please try a different search</h3>
          </div>
          <?php
        endif;
          ?>
    </div>

形象
//ACF场
没有找到任何项目
请尝试其他搜索
有人能告诉我如何在foreach循环中检索我的“产品”字段的值吗。 现在我没有收到任何错误,但我也没有收到任何价值


请提供帮助。

您必须了解有关分类术语字段的文档:

在你的情况下,你可以直接替换

回显_字段('product',$term->taxonomy);
由(3种可能性)

回显_字段('product',$term);
//或
回显_字段('product',$term->taxonomy._'.$term->term_id);
//或
回显_字段('product'、'term_uu'.$term->term_id);
如何从特定术语加载字段? 基本上,acf的加载字段是:
get\u字段('key',$post\u id)

对于分类术语,有3种不同样式的
$post\u id
可用,如下所示。(这来自acf文档)


echo get_字段('product',$term->taxonomy.'.'.'.$term->term_id)下面的答案是一个实际的答案,该人利用时间帮助你-我刚刚给出了一个可能的答案-给他工作所需的学分-很高兴我能提供帮助-我不太支持在评论中回答问题:-谢谢我的支持-抱歉“在评论中回答”
+----------------+----------------------------+-----------------------------------------------------------------------------+
| Example        | Format                     | Description                                                                 |
+----------------+----------------------------+-----------------------------------------------------------------------------+
| 'category_123' | $taxonomy . '_' . $term_id | A string containing the taxonomy name and term ID                           |
+----------------+----------------------------+-----------------------------------------------------------------------------+
| 'term_123'     | 'term_' . $term_id         | 'term_' . $term_id                                                          |
|                |                            | A string containing the word ‘term’ and term ID. Added in version 5.5.0     |
+----------------+----------------------------+-----------------------------------------------------------------------------+
| WP_Term        | $term                      | A term object. You can get a term object via many of WP’s functions such as |
|                |                            |                                                                             |
|                |                            | get_term()                                                                  |
+----------------+----------------------------+-----------------------------------------------------------------------------+