Home Forums General Issues get_field(); returns blank value


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

            $forside_slagord_stor = get_field('forside_slagord_stor');
            $forside_slagord_liten = get_field('forside_slagord_liten');
            $forside_slagord_liter = get_field('om_oss_tekst');
        <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>

    Here is my ACF setup

    Here is my ACF – Forside SETUP

  • 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
    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)

You must be logged in to reply to this topic.