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

How to include a JSON file on my page?

You can do this with PHP indeed. The steps are as followed; Get the contents of the JSON file within a variable using $json = file_get_contents(‘path-to-file.json’) Inside your <script> tags parse the JSON contents within a Javascript variable like this; var jsonContent=”<?= $json; ?>”; Debug the contents in your Javascript environment using the following; console.log(JSON.parse(jsonContent));

wp-json Returns 404 Upon Plugin Activation

I found the solution and will post here on the off-chance it helps someone in the future. The bottom line is there was a typo in a function that responded to POST requests. I narrowed it down to one file by disabling portions of my plugin in the activation class. By doing this I determined … Read more

How to add/edit advanced custom fields on custom post type’s WordPress REST API?

I think the only thing missing here is an update_callback in the call to register_rest_field. register_rest_field( ‘note’, ‘noteLink’, array( ‘get_callback’ => function(){ return get_field(‘page_link’); }, ‘update_callback’ => function( $value, $post ){ update_field(‘field_619dacfd37924’, $value, $post->ID ); } )); An important part of that according to ACF docs is using the field key to update the value … Read more

Custom JSON feed rewrite

The AJAX request would query for the dates it requires to display. With Lazy fetching set, if you switch from month to week or day views it won’t bother making another request, since it doesn’t need to. This is outlined in the fullcalendar documentation. As for using this method, see this question on how to … Read more

wordpress is adding a second backslash when I use addslashes

In your code json_encode() function causes to add second backslash on the following line. $data = json_encode($item_data); Add the following code in place of above code so it will replace double backslashes with single backslash in data returned by json_encode function. $data = str_replace(“\\\'”,”\\'”,json_encode($item_data )); Visit following links for more information on json_encode function. json_encode … Read more