admin管理员组文章数量:1323010
I'm trying to populate an ACF field on save (updating or creating the post) while running a geolocate function using mapbox. I'm getting a cannot modify header information error when hitting the update button.
Warning: Cannot modify header information - headers already sent by (output started at C:\****\public\wp-content\themes\***\mapbox\GeocodeResponse.php:22) in C:\****\public\wp-admin\post.php on line 223
My two files are brought in like this:
require_once get_template_directory() . '/mapbox/Mapbox.php';
require_once get_template_directory() . '/mapbox/custom-geocode.php';
Code in my custom-geocode.php:
function geolocate_test( $post_id ) {
$mapbox = new Mapbox("mykey");
$field_group = get_field('address');
$address = $field_group['line_1'] . ' ' . $field_group['line_2'] . ' ' . $field_group['city'] . ', ' . $field_group['state'] . ' ' . $field_group['zip'] . ' ' . $field_group['country'];
$res = $mapbox->geocode($address);
$long = $res[0]['center'][0];
$lat = $res[0]['center'][1];
$value = [
'latitude' => $lat,
'longitude' => $long
];
update_field('address', $value, $post_id );
}
add_action( 'save_post', 'geolocate_test' );
I'm using this same exact code elsewhere when updating taxonomies using, create_taxonomy & edit_taxonomy, so I'm not sure why I'm getting this error when saving/updating a post.
Any help is much appreciated!
本文标签: functionsSavepostWarning Cannot modify header information
版权声明:本文标题:functions - Save_post - Warning: Cannot modify header information 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742115646a2421455.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论