Wordpress ACF自定义字段未显示在自定义分类模板上
我创建了一个名为inn features的自定义分类法,然后创建了一个模板页面,每当我尝试显示自定义字段时,该值总是返回null。请有人告诉我哪里出了问题 这是一个非常简单的代码版本,因为我把所有的东西都去掉了,看看哪里出了问题,但我无法理解 每个变量的var转储显示以下内容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 $
<?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);
这个给我修好了