Dear all,
I am a new user of acf . Do you guys have any ideas and example for saving values from location field of a custom post type?
i m using acf v.5
and i have tried
function opt_update($ID, $post) {
$args = array(
'post_type' => 'point'
);
$opt_array = array();
$the_query = new WP_Query($args);
while ($the_query -> have_posts()): $the_query -> the_post();
array_push($opt_array, array(
'point_location' => get_field('point_location')
));
endwhile;
wp_reset_postdata();
file_put_contents($_SERVER['DOCUMENT_ROOT'] . '/wp-content/themes/test2/json/data.json', raw_json_encode($opt_array));
}
add_action('publish_post', 'opt_update', 10, 2);
it is not work for me~
Please let me know any ways to store specify field value into a Json file
thanks so much!
I have find the solution of it!
here is the code for share~
function my_acf_save_post( $post_id ) {
$args = array(
'post_type' => 'point'
);
$opt_array = array();
$the_query = new WP_Query($args);
while ($the_query -> have_posts()): $the_query -> the_post();
array_push($opt_array, array(
'point_location' => get_field('point_location')
)
);
endwhile;
wp_reset_postdata();
file_put_contents($_SERVER['DOCUMENT_ROOT'] . '/wp-content/themes/test2/json/data.json', json_encode($opt_array));
}
add_action('acf/save_post', 'my_acf_save_post', 10, 2);