Support

Account

Home Forums General Issues get_field(); returns blank value

Solved

get_field(); returns blank value

  • I got this WP installed with ACF Got a problem that getfield returns blank value.

    Heres my Code in front-page.php

    <?php
            $forside_slagord_stor = get_field('forside_slagord_stor');
            $forside_slagord_liten = get_field('forside_slagord_liten');
            $forside_slagord_liter = get_field('om_oss_tekst');
    ?>
        <header>
        <div class="container">
            <div class="intro-text">
                <div class="intro-lead-in"><?php echo $forside_slagord_stor;?></div>
                <div class="intro-heading"><?php echo $forside_slagord_liter;?></div>
                <a href="#services" class="page-scroll btn btn-xl">Tell Me More</a>
            </div>
        </div>
    </header>

    Here is my ACF setup
    https://postimg.org/image/y4c18z4tt/

    Here is my ACF – Forside SETUP
    https://postimg.org/image/8mtmpdn3l/

  • That is because, by the looks of things, you’re calling the function outside of the loop and ACF does not know what post to get the values from… that is unless you’re not including enough code form me to tell.

    Are you’re function calls inside “the loop” or outside.

    If you’re outside the loop then you can try something like this

    
    $queried_object = get_queried_object();
    $post_id = $queried_object->ID;
    $forside_slagord_stor = get_field('forside_slagord_stor', $post_id);
    $forside_slagord_liten = get_field('forside_slagord_liten', $post_id);
    $forside_slagord_liter = get_field('om_oss_tekst', $post_id);
    

    To be honest, I’m not sure that will work because there isn’t enough information to tell.

  • I changed to
    <?php
    global $post;

    $forside_slagord_stor = get_field(‘forside_slagord_stor’, $post->ID);
    $forside_slagord_liten = get_field(‘forside_slagord_liten’, $post->ID);
    $forside_slagord_liter = get_field(‘om_oss_tekst’, $post->ID);
    ?>

    And set “forside” to my static frontpage. than it worked. Thank you for your answer

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

The topic ‘get_field(); returns blank value’ is closed to new replies.