Home › Forums › Front-end Issues › Graph using the_field() only showing in first 2 posts and no others
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)
`
<!-- 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?
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.