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
- How to add a post page from a button without reloading
- Ajax load more post button not showing
- Using publish_{custom-post-type} hook for custom post type to update meta doesn’t work
- Put featured image under post title in admin area
- On saving Post My permalink is updated and category is removed automatically which cause the 404
- Best way to fix bad count on All | Mine | Published
- Why “Mine” is the default view when adding ‘capability_type’ in register_post_type
- Custom post type archive page filters
- Cannot manage to display my CPT in Recent Posts widget
- Create loop from selected terms in ACF taxonomy field
- Select custom post type do display from page editor
- update custom taxonomy custom fields
- Filter taxonomy by CPT
- Custom rewrite rule based on other custom post type title
- How to submit custom post type front end form when a user buy specific product
- Redirect Existing Post to CPT
- Order admin post list table by meta field, and have posts without the meta field always be at the end of the list
- Archive per year of a custom post getting the wrong post
- Alike Shortcode using in Custom Shortcode
- Get all post under custom post type grouped by custom filed value in custom taxonomy
- How to mass get post editor URLs
- Sort custom posts by date and then by taxonomy
- Grouping custom wordpress post types by acf value
- Get_post_custom not fetching value from array wordpress
- Custom Post Type add_rewrite_rule
- Add a form in every post and save data in post meta
- Post type to appear on every page on site
- Archive Post Not Showing All Post
- How to filter custom post type by multiple Taxonomies
- Get an array of the number of post per year of a custom post type (WordPress)
- WP Query: If field X is empty, show posts based on field Y
- automatically select taxonomy based on post meta
- Query custom post type that has a serialized relational advanced custom field value
- Order custom post type by taxonomy
- How to show related posts of category on post within custom posttype
- Saving custom JSON as custom post type