Support

Account

Home Forums Front-end Issues Graph using the_field() only showing in first 2 posts and no others

Helping

Graph using the_field() only showing in first 2 posts and no others

    • yasser

    • September 16, 2020 at 7:19 pm

    Hi guys, I am trying to add a graph on my wordpress website using a custom field. I call the field using the_field() then build the chart with anychart using the field as the input. However, the charts are only being generated for the first two posts and not any else.

    I tried changing the data input to the hardcoded values that are in the custom field and that works fine, so there is some issue calling it programmatically. This is within the single.php file.

    Does anyone know why this problem exists and why it happens for all posts except the first two?

    Here is the code and images of the problem (first image has the post where it works, but in the second you can see the graph is not loaded properly)

    https://imgur.com/a/IXlz0yQ

    `

    <!-- word map  -->
    
                        <script src="https://cdn.anychart.com/releases/v8/js/anychart-base.min.js"></script>
    
                        <script src="https://cdn.anychart.com/releases/v8/js/anychart-tag-cloud.min.js"></script>
    
                        <script>
    
                        anychart.onDocumentReady(function () {
    
                          var data = <?php get_field('wordmap_scores'); ?>;                                        
    
                          // create a tag cloud chart
                          var chart = anychart.tagCloud(data);
    
                          // set the chart title
                          // set array of angles, by which words will be placed
                          chart.angles([0])
    
                          // enable color range
                          chart.colorRange(false);
    
                          // set color range length
                          chart.colorRange().length('80%');
    
                          // display chart
                          chart.container("wordmap_display");
                          chart.draw();
                        });
                        </script>

    `

  • what should this look like on the page without the ACF call?

    
    var data = <?php get_field('wordmap_scores'); ?>; 
    

    what does the code in the page actually look like when the page is loaded with the ACf call?
    What kind of field is it and what is stored in it?

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

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.