<?php

function homegrade_brochure_post_title_updater($post_id)
{
	if (!$post_id) return;

	$my_post = array();
	$my_post['ID'] = $post_id;

	$fields = get_fields($post_id);
	if (!$fields) return;

	$brochureTaxonomy = $fields['publications_taxonomy'] ?? null;
	if (!$brochureTaxonomy) return;

	if (get_post_type() == 'brochures') {
		$my_post['post_title'] = "";
		$my_post['post_title'] = $brochureTaxonomy->name;
	}


	wp_update_post($my_post);
}
add_action('acf/save_post', 'homegrade_brochure_post_title_updater', 20);
