Im trying to get my form to push the text from a textfield to set it as the category
here is my code
function category_textfield( $post_id ) {
// Bail early if no ACF data
if( empty($_POST['acf']) ) {
return;
}
//array of category id's
$categoryIds = array();
//value of 'date' field is the cat_id
$cataname = get_field('set_category');
array_push($categoryIds, $cataname);
wp_set_post_categories($post_id, $categoryIds);
}
add_action( 'acf/save_post', 'category_textfield' );
but it doesnt seem to work, any suggestions
Hi @renshaw
Kindly have a look at the Pre save hook in acf
https://www.advancedcustomfields.com/resources/acfsave_post/
Hopefully this helps.