Upload data from weather station to WordPress Website

This is a pretty good application of WordPress’s REST API, which would enable you to update the data via a POST request containing the new data in JSON format and poll for changes with GET requests to the same endpoint. While you could establish this functionality with traditional AJAX request handlers, I think it makes … Read more

Adding inside wp-plugin jQuery script that receives JSON-formatted data, generated by php-function inside this plugin

Have a read of AJAX in Plugins, then see if you can adapt this code to what Highcharts is wanting: add_action(‘wp_ajax_wpse_77392_get_json’, ‘wpse_77392_get_json’); add_action(‘wp_ajax_nopriv_wpse_77392_get_json’, ‘wpse_77392_get_json’); function wpse_77392_get_json() { global $wpdb; $sql = ” SELECT `date`,`value` FROM {$wpdb->prefix}table_name WHERE `date` BETWEEN ‘2011’ AND ‘2012’ ORDER BY `date` ASC; “; $results = $wpdb->get_results($sql); $json = json_encode($results); header(‘Content-type: application/json’); … Read more

JSON API not showing full content

You can try this to show the full post content only in the JSON API: function remove_more_wpse_96740($content) { if(get_query_var(‘json’)){ global $post; $content = preg_replace(‘/<!–more(.*?)?–>/’,”,$post->post_content); } return $content; } add_filter(‘the_content’, ‘remove_more_wpse_96740’,1); by targeting the json query variable and remove the <!–more–> part of the post. If you have a custom string like <!–more But wait, there’s … Read more

Create WordPress posts from JSON array using plugin in admin

Here I assume your json is an array of object where properties are named like wp_insert_post arguments: ‘post_title’, ‘post_content’ and so on. function process_ajax() { if ( ! isset($_POST[‘nonce’]) || ! wp_verify_nonce($_POST[‘nonce’], ‘mynonce’) ) die(‘error on checking nonce’); if ( ! isset($_POST[‘filepath’]) die(‘no file given’); if ( ! file_exists($_POST[‘filepath’]) ) die(‘invalid file given’); $posts = … Read more

WP REST API. Configuring JSON routes

In the latest version of the API (2.0 ) the wp part is the namespace of core, default routes. This means that the core routes have URLs like “wp-json/wp/posts“, while a custom route would be something like “/wp-json/woo-comm/sizes“. The documentation just hasn’t caught up yet. Which version are you using?

Retrieve JSON file from JS trough php

I’m not convinced this is the cleanest way to do it but at least it work until I find something more efficient: function json_gmap(){ $get_file = file_get_contents(get_template_directory_uri() . ‘/data/my.json’); $json_to_array = json_decode($get_file,true); die (json_encode($json_to_array)); } add_action(‘wp_ajax_json_gmap’, ‘json_gmap’); add_action(‘wp_ajax_nopriv_json_gmap’, ‘json_gmap’); Basically I decode my Json file to an array and the re-encode it to have it … Read more

How can I modify the element on all pages?

The <header> elements are usually echoed directly by the theme. So without any hook or filter to change them. In that case, there is no way to change those elements with a function. Check your theme. You could, of course, use javascript to place you attributes, but that would happen on the user end. Search … Read more

Using wp_localize_script to get data from cpt and pass it to maplace-js locations

You don’t need to use json_encode() when using wp_localize_script(). The last argument of wp_localize_script() should be a PHP array. This will be converted to JSON for you. So to resolve the issue, remove this line: $location_json = json_encode($location_array); And change wp_localize_script() to use $location_array: wp_localize_script(‘sage/main.js’, ‘locationJSON’, $location_array); Because $location_array had been double-encoded the locationJSON variable … Read more

Prevent plugin from intruding on wp-json posts api

Basically what you would want is to disable the RPWE widget whenever a request is made through the API. I haven’t tested it, but this might work: add_action (‘widgets_init’, ‘wpse332374_remove_rpwe’, 0, 1000) // make sure this is the last action function wpse332374_remove_rpwe() { if (is_rest()) unregister_widget (‘recent_post_widget_extended’); // or whatever the handle is } Note … Read more