How to localize value of posts

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
}

Leave a Comment