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 was actually just a text string that looked like JSON. So when the Maplace script tried to access the first element of the array with locationJSON[0] it failed because the locationJSON variable was not actually an Array.
Related Posts:
- How to localize value of posts
- localize_script or rest api
- How to make sure, that only the selected post is changing?
- How to enqueue scripts on custom post add/edit pages?
- Fetch All Posts (Including Those Using a Custom Post Type) With WordPress API
- importing third party json feed as custom post type [closed]
- Full-Ajax Theme: parseJSON error while building a JSON object from a WordPress custom template
- Calculate Repeater Meta Box Input Field Values and Display Total
- How to create a repeatable / reusable divs in the metabox?
- Custom Scripts per page or Custom Post Type
- How do you use JavaScript to detect the homepage
- wp is not defined error using wp.media to create a custom image uploader
- WordPress Rest API only returns content when posttype has editor capability
- Recommended way to remove WP REST API returned data for custom post
- Open div inside a custom post-type with Fancybox
- Very simple wordpress block to display posts from an api call
- How to get the parent of a non-hierarchical custom post type being edited in Gutenberg
- Storing posts from query and accessing later via AJAX call
- Push metadata in array
- Save the post parent in a custom post type in Gutenberg
- Plugin – Combine Meta Box Input Fields into single saveble record
- JS innerhtml changing style when using AJAX
- Side effects of Script and Iframe in post
- Dynamic Custom Fields
- Multiple Frontend Filters Using Advanced Custom Fields
- Extracting Address from Custom Post via Javascript for Google Maps API
- How to add/edit advanced custom fields on custom post type’s WordPress REST API?
- Combine multiple getEntityRecords calls
- Custom Post Type Slick Slider “$ is not a function”
- Get data from PHP to JavaScript to set position of each post on front page
- Getting a GET error in console – 404 not found for wp-json
- Run shortcode in custom script in wp_head if post type is CPT ‘Jobs’
- Why is wp api returning old acf values?
- Importing JSON feed giving Notice: Array to string conversion error
- Loading multiple post content in FancyBox
- Weird issue where form field loses focus to previous form field even with JS disabled
- WordPress/Javascript form not working on custom post type single posts
- Create a Dropdown Selector and Redirect for a Custom Taxonomy in WordPress?
- How can I put content before my custom post type default pages?
- ForEach Loop iterates only once when inserting product variations
- Create/populate Custom Posts ACF fields from external JSON file
- URL issue retrieving Custom Post Types using Backbone JS API
- Publishing failed. The response is not a valid JSON response
- Randomizing WordPress Custom Post Type Sorting Through Them Without Page Refresh
- How can I use javascript in specific posts without relying on a plugin?
- How to use posts as tabs in a custom page?
- How to display “META” array in register_taxonomy
- Hide the update button from edit view in wordpress custom post type
- WordPress custom post type post item data – show/fetch only on click with Javascript dynamically?
- dynamic vue widget inside custom post
- Populating Custom Fields from live JSON
- How do I use URL to fetch all posts of a particular custom post type?
- Ajax WordPress pass post URLs
- WordPress API only returning HTML
- Convert Custom Post Data to Javascript Array for Autocomplete
- Redirect sub-page URLs to parent without changing URL
- How to get $post object available inside functions.php to localize script?
- Loops running into each other
- Appointment booking system in WordPress
- Passing total post count to javascript
- get total post in category via ajx
- Default post showing more than intended
- Load more post with AJAX
- Post current post type to my Ajax
- retrieving external api data and updating existing custom post
- How to intercept already localized scripts
- Can I change a custom post type label from a child theme?
- Get category id from post id of a custom post type
- Hide custom post type field from author?
- Permalink for CPT with taxonomy
- Add filter to wp_list_categories and query what type of taxonomy-terms it use?
- Custom post type category, taxonomy and URL rewrite problem
- Trying to save custom post type from frontend partially working
- Dropdown list of a custom post type
- How to display recent / random posts by its category
- Exclude specific taxonomy term when using wp_get_post_terms
- Custom Post Type with metaboxes (no content) only?
- Querying Term Posts in Loop
- One-to-many post relationships that are displayed by category (using posts-to-posts plugin)
- will post_id ever change? Can I safely use post_id for custom queries?
- Add Custom Post Type as top level menu item for a custom page
- How do I set a custom page template for a custom post type?
- Limit the Title Length on Custom Post Type Archive Page to a Set Number of Characters
- How to add a filter to a custom post type to get adjacent custom posts via the REST API
- I’m trying to create a custom version of the wp_list_authors function that includes custom post types
- Plain links in single-class.php and archive-class.php not working
- Custom post rewrite rule not working
- Why it doesn’t create a custom post type after form submitting
- What is the correct way that when creating a custom post type assign values to custom fields created with pods framework?
- Guided post type create based on category tree
- Advanced search form with multiple custom fields
- Custom Field Filter by Role – WordPress
- Adding Custom Taxonomy Along-with Post Name in Post Type Permalink
- archive.php can’t find categorized posts
- Submiting custom form give error 404
- Metabox textarea showing whitescreen
- How to loose the image ‘alt’ attribute in my custom post type?
- Cannot exclude particular post from loop of custom post type
- Custom archive URL as a subfolder of the custom post type slug
- How can I show a field ID in Elementor with Request Parameter