Try:
function register_and_enqueue_script()
{
if('myPostType' == get_post_type() && have_posts()) {
wp_register_script( 'js_script', plugin_dir_url(__FILE__).'js/script.js', array(), '1.8.5' );
wp_enqueue_script('js_script');
$myCustomValue = array();
while(have_posts()) {
the_post();
$mypostid = get_the_ID();
$myCustomValue[''.$mypostid] = nl2br(get_post_meta($mypostid, 'custom_value', true));
} // end while
rewind_posts();
wp_localize_script('js_script', 'myCustomValue', $myCustomValue);
} // end if
}
Related Posts:
- How to make sure, that only the selected post is changing?
- How to enqueue scripts on custom post add/edit pages?
- Using wp_localize_script to get data from cpt and pass it to maplace-js locations
- localize_script or rest api
- Is It Possible To Add Custom Post Type Menu As Another Custom Post Type Sub Menu
- Load a script just to custom post type in admin
- Create a custom archive page for a custom post type in a plugin
- Media library – Limit images to custom post type
- How to Add Custom Taxonomy To Woocommerce Plugin
- force enqueue script to be first in order of prominence
- Is there a JavaScript API? How to access public and private data in JS?
- Development of a WordPress Search Plugin – Best Practices
- Prevent trash/delete action on specific post types
- How to add custom content template part for a custom post type on main query using a plugin
- Change capability type of post type registered by plugin
- Rewriting ‘rewrite’ slug for custom post type used by plugin
- echo value from ‘select’ field type into page template using cmb2?
- register_taxonomy with multiple object type and update_count_callback
- wp_localize_script with boolean and init
- How often do you need to register_post_type?
- post_type_link filter causes 404 on the CPT page it’s used on
- How to use a dedicated template for the Custom Post Type from a plugin?
- Add Capabilities to Custom Post Type after it has been created [duplicate]
- Include images from pages in wp search.php results in default wp search
- Separating Search Results By Post Type
- List events by month
- How to add extra attributes to the script tag added via wp_localize_script()
- Date query for a custom meta field
- Maintaining WP_Query Relation Among CPT, Custom Taxonomy, Permalinks- CPT UI
- Change plugin’s has_archive = true to false?
- Getting arguments for register_post_type from a plugin generated post type
- update a post meta from a single table cell TablePress
- update custom post type meta from a shortcode
- Remove POST_TYPE from custom post type permalink
- Calculate Repeater Meta Box Input Field Values and Display Total
- Query posts between two dates (custom meta keys) CMB2
- Used with meta_query in query_posts works slowly
- Dequeue / Deregister script and replace it with a new plugin
- How to create a repeatable / reusable divs in the metabox?
- Custom Scripts per page or Custom Post Type
- Add extra parameter in tag using script_loader_tag
- Change upload_dir folder at a certain cpt but cant change back
- How do you use JavaScript to detect the homepage
- How to add post_author column to custom post type
- How to register custom post types in a plugin?
- WordPress/Javascript form not working on custom post type single posts
- Get localize of a loaded javascript
- Create a Dropdown Selector and Redirect for a Custom Taxonomy in WordPress?
- How can I put content before my custom post type default pages?
- URL issue retrieving Custom Post Types using Backbone JS API
- 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 pass data to javascript in custom widget class
- How to use posts as tabs in a custom page?
- Why can I not deregister my style and script on custom post type?
- Hide the update button from edit view in wordpress custom post type
- custom post type single page not found after aotumatic publish By the author’s robot
- Accessing download link from the loop with WP Download Manager Pro
- Set a template on a custom post in the plugin
- Simple way to hide\show an announcement (just a div) on homepage?
- WordPress custom post type post item data – show/fetch only on click with Javascript dynamically?
- Custom Post Type works when registered in functions.php but not when registered in plugin
- dynamic vue widget inside custom post
- Reading Custom Post data so I can have user update Manually
- Why is this function so slow?
- Permalink URL connection between two custom types
- How to show link to product in custom fields?
- Taxonomy counter on Taxonomy List(plugin)
- Is it possible to arrange Custom Post Types from CPTUI into a Folder?
- Restrict Custom Post Type to One Item
- Custom Post Type Front Page Gives 404
- Multiple useres editing specified content
- Show Post columns to specific users on condition
- Filter Custom Post Type Posts by Taxonomy
- Add input radio menu to post
- Disable ‘Add New’ in custom post that is made from CPT UI
- Insert custom taxonomy into category query
- Custom Post Type single post type shown in theme single.php
- CPT UI: Connect a custom post type to a custom post type
- Simple Data picker meta box
- How to check if a new private custom post type is created?
- Looping through image object using ACF and CPT UI [SOLVED]
- Default custom post type url
- Run query on specific admin options page and send results to select field in another function
- Link two different post using there post_id in post meta
- Custom post type that lets users create a set of posts?
- Include images from pages in wp search.php results in default wp search
- Create Inclusions and exclusions
- How to create groups like that in buddypress?
- Post that populates itself (almost) automatically using data from imported excel file
- I broke it! Custom post type archive gets redirected to home
- Populate metabox dropdown with post title from another Custom Post Type (issues with wp_reset / global $post)
- Custom Fields through plugin in a Custom Post Type
- Can’t save custom post type fields
- Enable shortcodes on custom post type
- Redirect sub-page URLs to parent without changing URL
- Multiple domains, Single database, 1 Parent/Master with all content, other domains/slaves with filtered content (based on “location” variable)
- How to Create movie schedule by custom post type query
- Best Plugins for Complex Index of Resources [closed]
- How to display all custom fields associated with a post type – IN THE ADMIN AREA?