Wordpress ACF get_field not loading












0















I've been racking my brain on this one. I've looked through the related stack overflow questions and yet can not seem to piece together this.



I am attempting to render a link using custom fields in WordPress and the get_field() function. I'm a new developer so I'm attempting to just console log it yet I keep returning "empty data" and "null" for my results. I understand get_field() will return 2 results, but I can't seem to extract my desired links. Any help is appreciated.



Custom fields:



image



This is my code base:



    $trend_one = get_field('trend_one');
$trend_two = get_field('trend_two');
$trend_three = get_field('trend_three');


?>
<div class='trend_bar'>
<div class="trend_item">TRENDING:</div>
<div class='trend_item'><?php console_log($trend_one); ?></div>
<div class='trend_item'><?php console_log($trend_two); ?></div>
<div class='trend_item'><?php console_log($trend_three); ?></div>
</div>









share|improve this question

























  • console.log is a javascript function. Not sure where you picked up console_log - but if it's a function you've written / added, you need to share that code. There's no need, really, though - In PHP, you'd use var_dump($trend_one) (or var_export). Note you may get recommendations to use echo or print_r, but those are limited - echo won't work for objects / arrays, and print_r will only work for objects / arrays, whereas var_dump or var_export will handle any variable contents.

    – cale_b
    Nov 21 '18 at 15:47













  • Please read how to create an Minimal, Complete, and Verifiable example - while your code is part of the equation, there's much more to the story, and if we don't know where you've put this code specifically, that could be the problem. get_field will only work in the right context (when the WP post has been set up), so knowing where in your template, which template, etc. matters.

    – cale_b
    Nov 21 '18 at 15:52











  • There are cases when the field name won’t work - in these cases you have to use field ID (that’s a long, unique code for the field, the ACF documentation tells you how to get it). And the other thing: try to set the second parameter of the get_field() function - that’s the post ID of the WP object whose ACF field you’re trying to get.

    – muka.gergely
    Nov 21 '18 at 18:24


















0















I've been racking my brain on this one. I've looked through the related stack overflow questions and yet can not seem to piece together this.



I am attempting to render a link using custom fields in WordPress and the get_field() function. I'm a new developer so I'm attempting to just console log it yet I keep returning "empty data" and "null" for my results. I understand get_field() will return 2 results, but I can't seem to extract my desired links. Any help is appreciated.



Custom fields:



image



This is my code base:



    $trend_one = get_field('trend_one');
$trend_two = get_field('trend_two');
$trend_three = get_field('trend_three');


?>
<div class='trend_bar'>
<div class="trend_item">TRENDING:</div>
<div class='trend_item'><?php console_log($trend_one); ?></div>
<div class='trend_item'><?php console_log($trend_two); ?></div>
<div class='trend_item'><?php console_log($trend_three); ?></div>
</div>









share|improve this question

























  • console.log is a javascript function. Not sure where you picked up console_log - but if it's a function you've written / added, you need to share that code. There's no need, really, though - In PHP, you'd use var_dump($trend_one) (or var_export). Note you may get recommendations to use echo or print_r, but those are limited - echo won't work for objects / arrays, and print_r will only work for objects / arrays, whereas var_dump or var_export will handle any variable contents.

    – cale_b
    Nov 21 '18 at 15:47













  • Please read how to create an Minimal, Complete, and Verifiable example - while your code is part of the equation, there's much more to the story, and if we don't know where you've put this code specifically, that could be the problem. get_field will only work in the right context (when the WP post has been set up), so knowing where in your template, which template, etc. matters.

    – cale_b
    Nov 21 '18 at 15:52











  • There are cases when the field name won’t work - in these cases you have to use field ID (that’s a long, unique code for the field, the ACF documentation tells you how to get it). And the other thing: try to set the second parameter of the get_field() function - that’s the post ID of the WP object whose ACF field you’re trying to get.

    – muka.gergely
    Nov 21 '18 at 18:24
















0












0








0








I've been racking my brain on this one. I've looked through the related stack overflow questions and yet can not seem to piece together this.



I am attempting to render a link using custom fields in WordPress and the get_field() function. I'm a new developer so I'm attempting to just console log it yet I keep returning "empty data" and "null" for my results. I understand get_field() will return 2 results, but I can't seem to extract my desired links. Any help is appreciated.



Custom fields:



image



This is my code base:



    $trend_one = get_field('trend_one');
$trend_two = get_field('trend_two');
$trend_three = get_field('trend_three');


?>
<div class='trend_bar'>
<div class="trend_item">TRENDING:</div>
<div class='trend_item'><?php console_log($trend_one); ?></div>
<div class='trend_item'><?php console_log($trend_two); ?></div>
<div class='trend_item'><?php console_log($trend_three); ?></div>
</div>









share|improve this question
















I've been racking my brain on this one. I've looked through the related stack overflow questions and yet can not seem to piece together this.



I am attempting to render a link using custom fields in WordPress and the get_field() function. I'm a new developer so I'm attempting to just console log it yet I keep returning "empty data" and "null" for my results. I understand get_field() will return 2 results, but I can't seem to extract my desired links. Any help is appreciated.



Custom fields:



image



This is my code base:



    $trend_one = get_field('trend_one');
$trend_two = get_field('trend_two');
$trend_three = get_field('trend_three');


?>
<div class='trend_bar'>
<div class="trend_item">TRENDING:</div>
<div class='trend_item'><?php console_log($trend_one); ?></div>
<div class='trend_item'><?php console_log($trend_two); ?></div>
<div class='trend_item'><?php console_log($trend_three); ?></div>
</div>






php wordpress advanced-custom-fields






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 15:30









Gufran Hasan

3,57241426




3,57241426










asked Nov 21 '18 at 15:28









Marsel GrayMarsel Gray

147




147













  • console.log is a javascript function. Not sure where you picked up console_log - but if it's a function you've written / added, you need to share that code. There's no need, really, though - In PHP, you'd use var_dump($trend_one) (or var_export). Note you may get recommendations to use echo or print_r, but those are limited - echo won't work for objects / arrays, and print_r will only work for objects / arrays, whereas var_dump or var_export will handle any variable contents.

    – cale_b
    Nov 21 '18 at 15:47













  • Please read how to create an Minimal, Complete, and Verifiable example - while your code is part of the equation, there's much more to the story, and if we don't know where you've put this code specifically, that could be the problem. get_field will only work in the right context (when the WP post has been set up), so knowing where in your template, which template, etc. matters.

    – cale_b
    Nov 21 '18 at 15:52











  • There are cases when the field name won’t work - in these cases you have to use field ID (that’s a long, unique code for the field, the ACF documentation tells you how to get it). And the other thing: try to set the second parameter of the get_field() function - that’s the post ID of the WP object whose ACF field you’re trying to get.

    – muka.gergely
    Nov 21 '18 at 18:24





















  • console.log is a javascript function. Not sure where you picked up console_log - but if it's a function you've written / added, you need to share that code. There's no need, really, though - In PHP, you'd use var_dump($trend_one) (or var_export). Note you may get recommendations to use echo or print_r, but those are limited - echo won't work for objects / arrays, and print_r will only work for objects / arrays, whereas var_dump or var_export will handle any variable contents.

    – cale_b
    Nov 21 '18 at 15:47













  • Please read how to create an Minimal, Complete, and Verifiable example - while your code is part of the equation, there's much more to the story, and if we don't know where you've put this code specifically, that could be the problem. get_field will only work in the right context (when the WP post has been set up), so knowing where in your template, which template, etc. matters.

    – cale_b
    Nov 21 '18 at 15:52











  • There are cases when the field name won’t work - in these cases you have to use field ID (that’s a long, unique code for the field, the ACF documentation tells you how to get it). And the other thing: try to set the second parameter of the get_field() function - that’s the post ID of the WP object whose ACF field you’re trying to get.

    – muka.gergely
    Nov 21 '18 at 18:24



















console.log is a javascript function. Not sure where you picked up console_log - but if it's a function you've written / added, you need to share that code. There's no need, really, though - In PHP, you'd use var_dump($trend_one) (or var_export). Note you may get recommendations to use echo or print_r, but those are limited - echo won't work for objects / arrays, and print_r will only work for objects / arrays, whereas var_dump or var_export will handle any variable contents.

– cale_b
Nov 21 '18 at 15:47







console.log is a javascript function. Not sure where you picked up console_log - but if it's a function you've written / added, you need to share that code. There's no need, really, though - In PHP, you'd use var_dump($trend_one) (or var_export). Note you may get recommendations to use echo or print_r, but those are limited - echo won't work for objects / arrays, and print_r will only work for objects / arrays, whereas var_dump or var_export will handle any variable contents.

– cale_b
Nov 21 '18 at 15:47















Please read how to create an Minimal, Complete, and Verifiable example - while your code is part of the equation, there's much more to the story, and if we don't know where you've put this code specifically, that could be the problem. get_field will only work in the right context (when the WP post has been set up), so knowing where in your template, which template, etc. matters.

– cale_b
Nov 21 '18 at 15:52





Please read how to create an Minimal, Complete, and Verifiable example - while your code is part of the equation, there's much more to the story, and if we don't know where you've put this code specifically, that could be the problem. get_field will only work in the right context (when the WP post has been set up), so knowing where in your template, which template, etc. matters.

– cale_b
Nov 21 '18 at 15:52













There are cases when the field name won’t work - in these cases you have to use field ID (that’s a long, unique code for the field, the ACF documentation tells you how to get it). And the other thing: try to set the second parameter of the get_field() function - that’s the post ID of the WP object whose ACF field you’re trying to get.

– muka.gergely
Nov 21 '18 at 18:24







There are cases when the field name won’t work - in these cases you have to use field ID (that’s a long, unique code for the field, the ACF documentation tells you how to get it). And the other thing: try to set the second parameter of the get_field() function - that’s the post ID of the WP object whose ACF field you’re trying to get.

– muka.gergely
Nov 21 '18 at 18:24














2 Answers
2






active

oldest

votes


















0














Why are you using console.log inside PHP?



It should be:



<?php echo $trend_one['url']; ?>
<?php echo $trend_two; ?>
<?php echo $trend_three; ?>


https://www.advancedcustomfields.com/resources/link/






share|improve this answer
























  • Thanks for wanting to help! Note that echo won't handle some variable types (arrays, objects, booleans) - may I suggest that you propose var_dump or var_export instead?

    – cale_b
    Nov 21 '18 at 15:48













  • @cale_b Hi, thanks. I wasn't sure if the OP is asking about the correct way to output the value, or the correct way to debug. Since console.log is not PHP, I thought the answer might be as simple as using echo. Shouldn't we get a PHP error, if we use console.log? - which is why I was a bit confused, how the code returns "null" or "empty data".

    – tadadadadi
    Nov 21 '18 at 16:16













  • Agreed on all points. My only point is that echo array(1,2,3); will display the word Array on the screen, and you might want to suggest var_dump instead :)

    – cale_b
    Nov 21 '18 at 16:19



















0














Here's that code you wanted for the console_log in PHP



function console_log( $data ) {
if ( empty( $data ) ){
print '<script>console.log("Empty Data");</script>';
print '<script>console.log(' . json_encode( $data ) . ');</script>';
} else {
if ( is_array( $data ) || is_object( $data ) ){
print '<script>console.table(' . json_encode( $data ) . ');</script>';
print '<script>console.log(' . json_encode( $data ) . ');</script>';

} else {
print '<script>console.log(' . json_encode( $data ) . ');</script>';
}
}


}






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53415354%2fwordpress-acf-get-field-not-loading%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Why are you using console.log inside PHP?



    It should be:



    <?php echo $trend_one['url']; ?>
    <?php echo $trend_two; ?>
    <?php echo $trend_three; ?>


    https://www.advancedcustomfields.com/resources/link/






    share|improve this answer
























    • Thanks for wanting to help! Note that echo won't handle some variable types (arrays, objects, booleans) - may I suggest that you propose var_dump or var_export instead?

      – cale_b
      Nov 21 '18 at 15:48













    • @cale_b Hi, thanks. I wasn't sure if the OP is asking about the correct way to output the value, or the correct way to debug. Since console.log is not PHP, I thought the answer might be as simple as using echo. Shouldn't we get a PHP error, if we use console.log? - which is why I was a bit confused, how the code returns "null" or "empty data".

      – tadadadadi
      Nov 21 '18 at 16:16













    • Agreed on all points. My only point is that echo array(1,2,3); will display the word Array on the screen, and you might want to suggest var_dump instead :)

      – cale_b
      Nov 21 '18 at 16:19
















    0














    Why are you using console.log inside PHP?



    It should be:



    <?php echo $trend_one['url']; ?>
    <?php echo $trend_two; ?>
    <?php echo $trend_three; ?>


    https://www.advancedcustomfields.com/resources/link/






    share|improve this answer
























    • Thanks for wanting to help! Note that echo won't handle some variable types (arrays, objects, booleans) - may I suggest that you propose var_dump or var_export instead?

      – cale_b
      Nov 21 '18 at 15:48













    • @cale_b Hi, thanks. I wasn't sure if the OP is asking about the correct way to output the value, or the correct way to debug. Since console.log is not PHP, I thought the answer might be as simple as using echo. Shouldn't we get a PHP error, if we use console.log? - which is why I was a bit confused, how the code returns "null" or "empty data".

      – tadadadadi
      Nov 21 '18 at 16:16













    • Agreed on all points. My only point is that echo array(1,2,3); will display the word Array on the screen, and you might want to suggest var_dump instead :)

      – cale_b
      Nov 21 '18 at 16:19














    0












    0








    0







    Why are you using console.log inside PHP?



    It should be:



    <?php echo $trend_one['url']; ?>
    <?php echo $trend_two; ?>
    <?php echo $trend_three; ?>


    https://www.advancedcustomfields.com/resources/link/






    share|improve this answer













    Why are you using console.log inside PHP?



    It should be:



    <?php echo $trend_one['url']; ?>
    <?php echo $trend_two; ?>
    <?php echo $trend_three; ?>


    https://www.advancedcustomfields.com/resources/link/







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 21 '18 at 15:45









    tadadadaditadadadadi

    135




    135













    • Thanks for wanting to help! Note that echo won't handle some variable types (arrays, objects, booleans) - may I suggest that you propose var_dump or var_export instead?

      – cale_b
      Nov 21 '18 at 15:48













    • @cale_b Hi, thanks. I wasn't sure if the OP is asking about the correct way to output the value, or the correct way to debug. Since console.log is not PHP, I thought the answer might be as simple as using echo. Shouldn't we get a PHP error, if we use console.log? - which is why I was a bit confused, how the code returns "null" or "empty data".

      – tadadadadi
      Nov 21 '18 at 16:16













    • Agreed on all points. My only point is that echo array(1,2,3); will display the word Array on the screen, and you might want to suggest var_dump instead :)

      – cale_b
      Nov 21 '18 at 16:19



















    • Thanks for wanting to help! Note that echo won't handle some variable types (arrays, objects, booleans) - may I suggest that you propose var_dump or var_export instead?

      – cale_b
      Nov 21 '18 at 15:48













    • @cale_b Hi, thanks. I wasn't sure if the OP is asking about the correct way to output the value, or the correct way to debug. Since console.log is not PHP, I thought the answer might be as simple as using echo. Shouldn't we get a PHP error, if we use console.log? - which is why I was a bit confused, how the code returns "null" or "empty data".

      – tadadadadi
      Nov 21 '18 at 16:16













    • Agreed on all points. My only point is that echo array(1,2,3); will display the word Array on the screen, and you might want to suggest var_dump instead :)

      – cale_b
      Nov 21 '18 at 16:19

















    Thanks for wanting to help! Note that echo won't handle some variable types (arrays, objects, booleans) - may I suggest that you propose var_dump or var_export instead?

    – cale_b
    Nov 21 '18 at 15:48







    Thanks for wanting to help! Note that echo won't handle some variable types (arrays, objects, booleans) - may I suggest that you propose var_dump or var_export instead?

    – cale_b
    Nov 21 '18 at 15:48















    @cale_b Hi, thanks. I wasn't sure if the OP is asking about the correct way to output the value, or the correct way to debug. Since console.log is not PHP, I thought the answer might be as simple as using echo. Shouldn't we get a PHP error, if we use console.log? - which is why I was a bit confused, how the code returns "null" or "empty data".

    – tadadadadi
    Nov 21 '18 at 16:16







    @cale_b Hi, thanks. I wasn't sure if the OP is asking about the correct way to output the value, or the correct way to debug. Since console.log is not PHP, I thought the answer might be as simple as using echo. Shouldn't we get a PHP error, if we use console.log? - which is why I was a bit confused, how the code returns "null" or "empty data".

    – tadadadadi
    Nov 21 '18 at 16:16















    Agreed on all points. My only point is that echo array(1,2,3); will display the word Array on the screen, and you might want to suggest var_dump instead :)

    – cale_b
    Nov 21 '18 at 16:19





    Agreed on all points. My only point is that echo array(1,2,3); will display the word Array on the screen, and you might want to suggest var_dump instead :)

    – cale_b
    Nov 21 '18 at 16:19













    0














    Here's that code you wanted for the console_log in PHP



    function console_log( $data ) {
    if ( empty( $data ) ){
    print '<script>console.log("Empty Data");</script>';
    print '<script>console.log(' . json_encode( $data ) . ');</script>';
    } else {
    if ( is_array( $data ) || is_object( $data ) ){
    print '<script>console.table(' . json_encode( $data ) . ');</script>';
    print '<script>console.log(' . json_encode( $data ) . ');</script>';

    } else {
    print '<script>console.log(' . json_encode( $data ) . ');</script>';
    }
    }


    }






    share|improve this answer




























      0














      Here's that code you wanted for the console_log in PHP



      function console_log( $data ) {
      if ( empty( $data ) ){
      print '<script>console.log("Empty Data");</script>';
      print '<script>console.log(' . json_encode( $data ) . ');</script>';
      } else {
      if ( is_array( $data ) || is_object( $data ) ){
      print '<script>console.table(' . json_encode( $data ) . ');</script>';
      print '<script>console.log(' . json_encode( $data ) . ');</script>';

      } else {
      print '<script>console.log(' . json_encode( $data ) . ');</script>';
      }
      }


      }






      share|improve this answer


























        0












        0








        0







        Here's that code you wanted for the console_log in PHP



        function console_log( $data ) {
        if ( empty( $data ) ){
        print '<script>console.log("Empty Data");</script>';
        print '<script>console.log(' . json_encode( $data ) . ');</script>';
        } else {
        if ( is_array( $data ) || is_object( $data ) ){
        print '<script>console.table(' . json_encode( $data ) . ');</script>';
        print '<script>console.log(' . json_encode( $data ) . ');</script>';

        } else {
        print '<script>console.log(' . json_encode( $data ) . ');</script>';
        }
        }


        }






        share|improve this answer













        Here's that code you wanted for the console_log in PHP



        function console_log( $data ) {
        if ( empty( $data ) ){
        print '<script>console.log("Empty Data");</script>';
        print '<script>console.log(' . json_encode( $data ) . ');</script>';
        } else {
        if ( is_array( $data ) || is_object( $data ) ){
        print '<script>console.table(' . json_encode( $data ) . ');</script>';
        print '<script>console.log(' . json_encode( $data ) . ');</script>';

        } else {
        print '<script>console.log(' . json_encode( $data ) . ');</script>';
        }
        }


        }







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 21 '18 at 15:59









        Marsel GrayMarsel Gray

        147




        147






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53415354%2fwordpress-acf-get-field-not-loading%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

            SQL update select statement

            'app-layout' is not a known element: how to share Component with different Modules