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
- Remove Custom Taxonomy Metabox from Custom Post Type Screen
- How can I change the admin search posts fields?
- Creating conditional blocks for WordPress Gutenberg
- Removing base slug from hierarchical custom post type
- Highlight menu item when on a custom post type?
- Querying custom posts and regular posts
- Post slug changed using code doesn’t reflect on editor when post is published
- Detect meta value changes when post is updated (post_updated)
- How to show particular category all post in custom single file
- How to remove ‘create new post’ entry for a custom post type?
- Changing ‘view’ link for custom post type on list post screen?
- WordPress nl2br is not converting newline to html line break when saving metabox value
- Create custom PAGE with register_post_type
- Update CPT post meta with update_post_meta and cron job
- Calculate all custom field values in the post loop
- Rewrite post type slug only for child theme
- Assign same parrent Page to pages AND custom post types
- wordpress remove views from action links in a custom post
- archive as a page, so that it can be added in the wp_menu_nav
- singular_name label in custom post type
- Different post title, keywords and description
- Get Terms from Custom Taxonomy and Current Post
- Catch and display error on save_post action
- How to display related posts using the same taxonomy for custom types (WordPress, Pods, Woo)
- Filter custom post type admin list by custom meta column, where the column is another custom posts meta value
- Is there a way to create a sidebar of bullets
- From CPT Custom Loop into Shortcode?
- Set a Default CPT taxonomy by taxonomy id
- Skip latest 3 posts from loop
- Custom taxonomy terms registered not showing when added in child theme
- How to redirect from wp-admin/edit.php to a frontend page for specific custom post type?
- Display all Custom taxonomy terms and their relevant custom posts
- wordpress query_posts with foundation 6 Accordion not working correctly
- How to remove UI access to Custom Post Type using direct links?
- get_post_types doesn’t work in plugin
- Would like to add a “leaderboard” (custom field) to a custom post type
- I have a custom post type that I want to query a dynamic category name from a custom meta field
- Is it possible to make one of two custom fields in Custom Post Type UI Required but not the other?
- adding a shortcode into a custom post type
- using a template for more then 1 page
- Add word limit in wordpress posts editor
- wordpress custom post type shows other cpt posts in admin menu