Support

Account

Home Forums Front-end Issues get_field doesn't work in frontend

Solving

get_field doesn't work in frontend

  • Hi,

    I got things all set up correctly in the Admin, everything just working fine. Now in my frontend, I don’t get anything returned from the_field() or get_field() calls, while the_meta() produces valid data. So I dug into core/api.php and found the following:

    1. $GLOBALS[‘acf_register_field_group’] is empty, unless I export the fields to PHP include the result into functions.php. Is that actually a requirement?

    2. The $field_key passed into api_acf_load_field for a get_field(‘job_title’) call is ‘field_job_title’, while the key that is being searched for is ‘field_54d0db0eb17b5’

    So even with the exported PHP code in functions.php, it still doesn’t work. What am I doing wring? I do have to mention that I set up the custom field in 4.3.9, while this afternoon I upgraded to 4.4.0 before starting on the frontend.

    Thanks

    -edit-

    I resolved this by changinh api.php:39

    $return = get_post_meta($post_id, '_' . $field_name, true);

    into

    $return = get_post_meta($post_id, $field_name, true);

    Not sure if that’s the right way though..

  • Hi,

    if you’re trying to get the custom field value you should just echo it like this:

    <?php 
        $var = get_the_field('your-custom-field');
    ?>
    <p><?php echo $var; ?></p>
    

    Does it help?

  • no the get_the_field function doesn’t exist in (my instance of) ACF.

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘get_field doesn't work in frontend’ is closed to new replies.