Advanced Custom Fields: Call to undefined function get_field()

Viewed 4084

If I try to use ACF inside my custom functions plugin I get this error:

Uncaught Error: Call to undefined function get_field() in

I created my custom function plugin to avoid using the default functions.php that comes with the theme, because it overrides on every update.

My code:

<?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']; ?>" />

I'm using a Gantry5 theme.

I already followed the documentation and read some posts with examples, but even so I’m not being able to get it working. The field is set as User Object.

UPDATE:

I found this code in the developer's website, I'm going to be giving it a try. This code supposed to allow ACF (free version) to be loaded inside a plugin.

// 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/

Second Update: Still having the same problem.

0 Answers
Related