Support

Account

Home Forums Backend Issues (wp-admin) How to save a json file of location field data of each custom post? Reply To: How to save a json file of location field data of each custom post?

  • 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);