The data passed by wp_localize_script()
is output in a <script>
tag in the page HTML. So if you have this:
wp_localize_script( 'registered_script', 'serverData', array( 'posts' => $post_array ) );
This will be on the page:
<script type="text/javascript">
/* <![CDATA[ */
var serverData = { "posts": [] };
/* ]]> */
</script>
This means that if your page HTML is cached with something like WP Super Cache or WP Rocket this data will also be cached. So if you need the data to be 100% up to date, to the second, then you should retrieve fresh data via AJAX in your script.
Keep in mind that wp_localize_script()
was originally designed to provide localized/translated strings to scripts, and those don’t need to be updated anywhere near that frequently.
Related Posts:
- What is the correct way to build a widget using OOP
- wp_localize_script $handle
- WP_LOCALIZE_SCRIPT doesn’t work
- Use of global variables within plugin [closed]
- How to localize admin.php only once
- Update Data parameter of a wp_localize_script() call
- Translate javascript with WordPress built-in localization API for static strings
- Use options to control jQuery plugin
- How to localize data array in plugin’s option page
- Ajax Response Error | just getting error as the response
- mutiple shortcode instance on the same page
- How can I add an image upload field directly to a custom write panel?
- Creating a table in the admin-style?
- What process do you use for WordPress development? [closed]
- How do I create a custom role capability?
- How to return only certain fields using get_posts()
- Where to put third party PHP library?
- Add a new tab to WordPress Plugin install Listing
- Export data as CSV in back end with proper HTTP headers
- Scheduled events disappear from events queue
- How to integrate a PHP webmail script into the backend of WordPress?
- How to log plugin errors to plugin error_log file
- Custom Post Type Link from Plugin
- How to Get a List of Sub Blogs without Using get_blog_list()?
- Using wp_cron with custom time interval and the register activation hook
- Conditional check to see if a bootstrap.css is included in a theme
- Throw 403 in a plugin [duplicate]
- WordPress multisite apply different options over each site from same plugin
- Using ob_start() in plugin
- Create Element From Dynamic HTML String [closed]
- Can I add pages to my custom menu via script?
- How can I view all WP generated thumbnails in Media Manager?
- Only allow plugin to be activated on root site of multisite
- what is the best practice for including ‘wp-includes’ classes
- Programmatically Selecting Theme Based on URL
- Custom Plugin Database relations
- Save user-specific options in WordPress admin
- Why is print_r returning $classObj->userObj in several places on site
- How can i get the title i specified in add_options_page for my header
- use __($str) to translate strings (symfony/twig)
- Plugin development: is adding empty index.php files necessary?
- Is there a way to list tags order by post_meta field
- how to redirect to another post without getting headers already sent error?
- Customize multisite site creation with user data
- Mixing Regular Javascript With jQuery in a Plugin
- Best plugin for most viewed post [closed]
- What could cause my plugin’s options/settings page not to load?
- Plugin Upgrade Strategy
- Which are the hooks run before/after when a category’s deletion?
- Disable The Events Calendar plugin from loading its scripts
- get_the_excerpt() not working in plugin loop
- How to remove images from my plugin page in WP Directory?
- Is there an additional block.json property to set to get an InnerBlocks child to respect the “supports” property?
- Plugin with action ‘save_post’ needs to press publish twice on order to publish
- How to prevent UNDO on guternberg block editor
- woocommerce_checkout_order_processed hook executing function twice
- How to analyze wordpress plugin performance
- On the .org repo, can your plugin name/slug contain “WooCommerce” [closed]
- Wrap text around shortcode
- Checked() function on a multidimensional array
- Plugin does not add action
- Jquery was not found on this server
- Plugin language always shows WP site language, not profile language
- How to create a digital product download link that can’t be used twice?
- Creating an installation zip file
- update_callback is not working in register_rest_field
- How to create ShortCode
- Reporting errors in a shortcode plugin
- shortcode tags not working in do_shortcode
- Working of foreach loop with array
- Why is the form not updating when I select a new sector from the list?
- How to change a field in database through a submit button or Checkbox? [closed]
- Grandchildtheme (plugin) add header.php (not exist in child theme)
- How do I add a menu item to a Pods admin menu?
- $wpdb->update Issue
- Import images remotly run through timeout error
- How to make every image title equal to alt text(wordpress/woocommerce)?
- Load specific page when a custom URL is hit
- Getting incorrect filepath inside custom block front-end output using @wordpress/create-block tutorial
- HTMLCollection not counting right in editor? / for loop not working on elements in DOM
- Trying to rename a file upload as the hash of file content on wordpress
- Getting products information, in woocommerce based on products ID
- Fatal error: Uncaught Error: Using $this when not in object context
- How can I measure CPU and RAM used by my theme or plugin
- want to confirm popup with “Yes” and “No” button when user click on add to cart
- set a custom post type to a taxonomy term programmatically in metabox
- Modify search form with plugin
- How to display properly exception or echo string after posting in plugin?
- How can I add recent posts to menu like mashable
- When using an options array the Settings API isn’t creating the database record
- the correct way to use options from settings page [closed]
- Changing upload directory for plugin uploads only
- How do I query posts and have their related taxonomies returned in the results?
- On one of my sites a file is shown as 404 but the file IS there
- $_GET vs get_query_var()
- Extend WP_List_Table class – Edit wp_usermeta – WPPB.me Boilerplate – Action error
- Anyway to prevent admin from seeing other admin’s product?
- Build a dynamic block using the default attributes
- Bulk post approval and publishing doesn’t work
- Show Admin Menu