I am using AM Charts to create some charts for me and this utilises data from CSV files. To make this easy for the website owner keep this up to date I am trying to enable an options page so they can upload a new css file.
The current code collecting the data is :
chart.dataSource.url = "../wp-content/uploads/2021/05/sample_data_serial.csv";
I have tried adding the below to replace the above but I cannot get this to work – where am I going wrong?
var datafile = <?php echo the_field('gas_data_file', 'option'); ?>;
How do I get that field output to replace the data file as shown above??
chart.dataSource.url = ??????????
Thanks in advance.
Hi John ….
Thanks for your help.
chart.dataSource.url = “../wp-content/uploads/2021/05/sample_data_serial.csv”;
chart.dataSource.url = “<?php echo the_field(‘gas_data_file’, ‘option’); ?>”;
or if I have to something more fancy like I have seen in a few support posts already (sorry Java is not my forte…) like create a value from :
var datafile = <?php echo the_field(‘gas_data_file’, ‘option’); ?>;
and then add this in to the Java …. if so, it is here I am not sure how to write this last element.
this looks like a script that is included using a script tag with an url like.
PHP to output anything to do with WP cannot be added to such a script. To add directly to this you would need to output the script inside of a template file something like
?> <script> // code of script here. </scrip> <?php
So that it is part of the HTML page and not a separate .js file
To add variable values to the type of script you are using it must be registered, localized and enqueued using WP hooks and actions https://developer.wordpress.org/reference/functions/wp_localize_script/
Hi John ….
Once again, many thanks for your response. Will have a play and try and teach myself.
However, had another idea and found an article you wrote in 2016 and have found a way around it for now. I have added the upload_prefilter to rename the file and also change the destination for the upload – therefore the csv filename and location will be constant.
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!
Now that we've released this update, we recommend updating your sites as soon as possible.
© 2022 Advanced Custom Fields.