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
Wordpress ACF自定义字段未显示在自定义分类模板上_Wordpress_Advanced Custom Fields_Custom Taxonomy_Acfpro - Fatal编程技术网

Wordpress ACF自定义字段未显示在自定义分类模板上

Wordpress ACF自定义字段未显示在自定义分类模板上,wordpress,advanced-custom-fields,custom-taxonomy,acfpro,Wordpress,Advanced Custom Fields,Custom Taxonomy,Acfpro,我创建了一个名为inn features的自定义分类法,然后创建了一个模板页面,每当我尝试显示自定义字段时,该值总是返回null。请有人告诉我哪里出了问题 这是一个非常简单的代码版本,因为我把所有的东西都去掉了,看看哪里出了问题,但我无法理解 每个变量的var转储显示以下内容 <?php /** * The template for displaying taxonomy archive pages * */ // get the current taxonomy term $

我创建了一个名为inn features的自定义分类法,然后创建了一个模板页面,每当我尝试显示自定义字段时,该值总是返回null。请有人告诉我哪里出了问题

这是一个非常简单的代码版本,因为我把所有的东西都去掉了,看看哪里出了问题,但我无法理解

每个变量的var转储显示以下内容

<?php
/**
 * The template for displaying taxonomy archive pages
 *
 */



// get the current taxonomy term
$queried_object = get_queried_object(); 
$taxonomy = $queried_object->taxonomy;
$term_id = $queried_object->term_id;  



// vars
$test = get_field('test_text', $taxonomy);

    var_dump($queried_object);

    var_dump($taxonomy);

    var_dump($term_id);

    var_dump($test);

    ?>



$queryed\u object、$taxonomy&$term\u id所有返回值纯$test返回null。

您需要为第二个参数使用post id

根据ACF的文件:

get_field($selector, [$post_id], [$format_value]);
因此,您需要在分类法中循环浏览帖子,然后显示每个帖子的自定义字段


我最终通过以下方式解决了问题:

$term = get_queried_object();

$test = get_field('test_text',$term);
这个给我修好了