Fetch data from json file to wordpress
-
This post is deleted! -
I found this fetch method. Let's say the json file link is: https://testsite.com/myproductversion.json
fetch('https://testsite.com/myproductversion.json').then(res => res.json()) .then(({ MajorVersion, MinorVersion, MaintenanceVersion }) => { let version = `v${MajorVersion}.${MinorVersion}.${MaintenanceVersion}`; $('.my-version-goes-here').html(version); }).catch(console.error);
How this method can be used in html?
-
@Steve-Mohican HTML is not a programming language, you can't do things like that with it. I recommend you hire a WordPress developer on fivver.
-
@Steve-Mohican - just use a text editor on your own machine then upload it with an FTP client.
-
@Steve-Mohican Did you find a solution for this?
-
@Fortune said in Fetch data from json file to wordpress:
@Steve-Mohican Did you find a solution for this?
the solution is right above your post....
-
@Fortune said in Fetch data from json file to wordpress:
@Steve-Mohican Did you find a solution for this?
@Fortune Not yet. I haven't hired a developer for that. But I plan to find one in fiverr like @d-healey advised.
After that I will follow to upload with an FTP client like @Lindon -
@Steve-Mohican @Fortune
Here you go :D There could be a better implementation, but this is what I use for this purpose.Below is the HTML code, I don't know which wordpress composer plugin you're using but you need to put this code into an HTML editor (standart Gutenberg Text editor might not work). Then you need to upload your json file (named as version.json here) into your server just like @Lindon said.
Also you need to customize your div, .p and .currentversiondisplayer css styles (the container div tag is versiondisplayer_container here)
If you don't want to work online at the begining, you can use XAMPP for local server system by the way ;)
<script src="https://code.jquery.com/jquery-3.6.0.js" crossorigin="anonymous"></script> <div class="versiondisplayer_container"> <p>Current Version: </p> <p id="productA_currentversiondisplayer"></p> </div> <script> $(document).ready(function() { fetch('/SubFolderOfTheJsonFile/version.json') .then(response => response.json()) .then(data => $('#productA_currentversiondisplayer').html((data.MajorVersion+'.'+data.MinorVersion+'.'+data.MaintenanceVersion))); }); </script>
Like you want, the JSON file is this:
{ "Name": "MyProduct", "MajorVersion": "1", "MinorVersion" : "0", "MaintenanceVersion" : "0" }
Example usage is here (shows up in the "Current Version" section): https://www.noiseash.com/downloads/
-
@orange Wow! That's it man :D
Thank you so much!!!! -
@orange thanks a lot dude, you're awesome :)