Google places search box save to meta box nonce

I’m trying to add Google places search box as a meta box in my custom post as a new nonce. The input field itself is working, but when I’m adding the value attribute to it, I’m getting this Error: Cannot read property ‘value’ of null at new l6 (places_impl.js:9). Any ideas how to solve it?
My code:

function iz_property_address_search_callback($post)
{
    wp_nonce_field('iz_save_property_address_search_data', 'iz_property_address_search_meta_box_nonce');
    $value = get_post_meta($post->ID, '_property_address_search_value_key', true);

    echo '<label for="iz_property_address_search_field">Propery Address Search: </label>';
    echo '<input id="pac-input" class="controls" type="text" name="iz_property_address_search_field" value="' . esc_attr($value) . '" size="50">';

}

/**
 * Save the property address search
 * @param $post_id - the current post id
 */
function iz_save_property_address_search_data($post_id)
{
    //check if the nonce is set
    if (!isset($_POST['iz_property_address_search_meta_box_nonce'])) {
        return;
    }

    //check if nonce is valid
    if (!wp_verify_nonce($_POST['iz_property_address_search_meta_box_nonce'], 'iz_save_property_address_search_data')) {
        return;
    }

    //check if its an auto save and don't save if it is
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
        return;
    }

    //check user peormission to edit the post
    if (!current_user_can('edit_post', $post_id)) {
        return;
    }

    //check if the address field is set
    if (!isset($_POST['iz_property_address_search_field'])) {
        return;
    }

    $my_data = sanitize_text_field($_POST['iz_property_address_search_field']);
    update_post_meta($post_id, '_property_address_search_value_key', $my_data);
}

Read more here: Google places search box save to meta box nonce

Leave a Reply

Your email address will not be published. Required fields are marked *