
Using ACF pro and saving all posts to json files for a project.
Is there a way to find all custom fields on a posts’ page? We’re dealing with a lot of custom post types and fields.
It would be easier if we could just get any fields and their data assigned to a post instead of specifying all the fields per post type manually.
I’ll then add it to the post object.
thanks!
function on_post_publish($ID, $post)
{
$data = json_encode($post);
$upload_dir = wp_upload_dir();
$path = $upload_dir['basedir'] . "/json/";
$pt = str_replace('pmdd_cpt_', '', $post->post_type);
$file_name = "PMDD_" . $pt . '_' . $ID . '.json';
// echo $path . $file_name;
if ($post->post_type == 'pmdd_cpt_data_source'):
file_put_contents($path . $file_name, $data);
$ds_data = data\choose_data($ID);
$file_name_data = "PMDD_" . $pt . '_' . $ID . '_data.json';
file_put_contents($path . $file_name_data, $ds_data);
update_field('pmdd_ds_cache_updated', current_time('mysql'));
else:
endif;
}
add_action('save_post', __NAMESPACE__ . '\\on_post_publish', 10, 2);