如何解决高级自定义字段:调用未定义的函数 get_field()
Uncaught Error: Call to undefined function get_field() in
我创建了自定义函数插件,以避免使用主题附带的默认 functions.PHP,因为它会在每次更新时覆盖。
我的代码:
<?PHP
$author_id = get_the_author_Meta('ID');
$author_badge = get_field('post_autor','user_'. $author_id );
?>
<img src="<?PHP echo $author_badge['url']; ?>" alt="<?PHP echo $author_badge['alt']; ?>" />
我使用的是 Gantry5 主题。
我已经按照文档阅读了一些带有示例的帖子,但即便如此,我还是无法让它工作。该字段设置为 User Object
。
更新:
我在开发者的网站上找到了这段代码,我打算试一试。这段代码应该允许在插件中加载 ACF(免费版)。
// Define path and URL to the ACF plugin.
define( 'MY_ACF_PATH',get_stylesheet_directory() . '/includes/acf/' );
define( 'MY_ACF_URL',get_stylesheet_directory_uri() . '/includes/acf/' );
// Include the ACF plugin.
include_once( MY_ACF_PATH . 'acf.PHP' );
// Customize the url setting to fix incorrect asset URLs.
add_filter('acf/settings/url','my_acf_settings_url');
function my_acf_settings_url( $url ) {
return MY_ACF_URL;
}
// (Optional) Hide the ACF admin menu item.
add_filter('acf/settings/show_admin','my_acf_settings_show_admin');
function my_acf_settings_show_admin( $show_admin ) {
return false;
}
https://www.advancedcustomfields.com/resources/including-acf-within-a-plugin-or-theme/
第二次更新: 还是有同样的问题。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。