I get the following error and white screen of death when I try submit the front end form:
Warning: Invalid argument supplied for foreach() wp-includes/post.php on line 3471
The only way I can get a successful submission is to either, be logged in, or remove:
'tax_input' => 'featured'
Has anyone else encountered this?
This needs to be in the form specified for wp_insert_post() https://codex.wordpress.org/Function_Reference/wp_insert_post
example
'tax_input' => array(
// taxonomy => terms
'category' => 'featured'
)
Because the filter pre_save acf has been disabled in the version 5? I need him to handle taxonimias of this model in my post, among several outroso fields I used to save.
Is there another way of doing?
This is my code
function salvar( $post_id ) {
return $post_id;
echo "<script> alert('Ok Joao'); </script>";
$field = $_POST['acf'];//resume a chamada do form
$form_type = $field['form_type'];//diz qual é a CTP que deve guardar
// check if this is to be a new post
if( $post_id != 'new_post' ) {
switch ($form_type) {
case 'advert':
//Tratamento das Cidades como Taxonomias
$exist_state = term_exists( $field['field_569b07ac73afc'], 'estado_cidade' );
if( $exist_state == 0 && $exist_state == null){
$state = array(
'description'=> 'Encontre anuncios em '. $field['field_569b07ac73afc'] ,
'slug' => sanitize_title($field['field_569b07ac73afc']),
//'parent'=> $parent_term_id
);
$state_save = wp_insert_term($field['field_569b07ac73afc'], 'estado_cidade', $state );
$state_save = $state_save['term_id'];
}else{
$state_save = get_term_by('id', $field['field_569b07ac73afc'], 'estado_cidade' );
}
$exist_city = term_exists( $field['field_569b07c873afd'], 'estado_cidade' );
if($exist_city == 0 && $exist_city == null){
$cidade = array(
'description'=> 'O ADVirtual oferece diversos anuncios em '. $field['field_569b07c873afd'] ,
'slug' => sanitize_title($field['field_569b07c873afd']),
'parent'=> $estado_save
);
$city_save = wp_insert_term($field['field_569b07c873afd'], 'estado_cidade', $cidade );
$city_save = $city_save['term_id'];
}else {
$city_save = get_term_by('id', $field['field_569b07c873afd'], 'estado_cidade' );
}
$taxcidade = array(
'estado_cidade' => array( $city_save )
);
//echo "<script> alert('".$taxcidade."'); </script>";
$post = array(
'ID' => $post_id,
'post_type' => 'advert',
'post_status' => 'draft',
//'post_author' => $logged->ID,
'tax_input' => $taxcidade
);
//insert the post
$post_id = wp_update_post( $post );
return $post_id;
break;
// case 'pratos_post':
// $form_type = 'pratos_post';
// $parent_term = term_exists( sanitize_title($field['tax']), 'estado_cidade' ); // array is returned if taxonomy is given
// $parent_term_id = $parent_term['term_id'];
// $postData = array(
// 'ID' => $field['postid'],
// 'post_title' => $field['field_55af07dfa7866'],
// 'post_name' => sanitize_title($field['field_55af07dfa7866']),
// 'tax_input' => array(
// 'estado_cidade' => array( $parent_term_id ),
// ),
// );
// wp_update_post($postData);
// break;
// case 'perfil':
// // $postDataUser = array(
// // 'ID' => $field['postid'],
// // );
// // wp_update_user($postDataUser);
// $parent_term = term_exists( sanitize_title($field['field_55b6f5b7f6329']), 'estado_cidade' ); // array is returned if taxonomy is given
// $parent_term_id = $parent_term['term_id']; // get numeric term id
// $e = array(
// 'description'=> 'Encontre pratos delicioso a partir de R$20,00 por pessoas em '. $field['field_55b1c5c76e666'] ,
// 'slug' => sanitize_title($field['field_55b1c5c76e666']),
// 'parent'=> $parent_term_id
// );
// wp_insert_term($field['field_55b1c5c76e666'], 'estado_cidade', $e );
// break;
//Salvamento das imaegens em função externa ao ACF
default:
echo "<script> alert('Problema ao editar os dados'". $form_type ."); </script>";
break;
}
}else{
//se nao for novo cai pra cá
switch ($form_type) {
case 'user':
$user_email = email_exists($field['field_569a597e95338']);
if ( $user_email) {
//$user = get_user_by( 'email', $user_email );
echo "<script> alert('Usuario'". $user->ID .");";
$creds = array();
$creds['user_login'] = $field['field_569a597e95338'];
$creds['user_password'] = $field['field_569a597e95338'];
$creds['remember'] = false;
$user = wp_signon( $creds, false );
$logged = get_user_by( 'email', $field['field_569a597e95338'] );
$logged = $logged->ID;
echo "<script> alert('Usuario logado'); </script>";
wp_redirect( site_url('/ad?email='. $field['field_569a597e95338'] .'&author_id='. $logged ) ); exit;
//return 'user_'. $user->ID;
}else{
$postDataUser = array(
'ID' => $user_id,
'user_login' => $field['field_569a597e95338'],
'user_email' => $field['field_569a597e95338'],
'user_pass' => $field['field_569a597e95338'],
'role' => 'advertiser'
);
//register user
$user_id = wp_insert_user($postDataUser);
//$user_id = 'user_'.$user_id;
if($user_id){
$creds = array();
$creds['user_login'] = $field['field_569a597e95338'];
$creds['user_password'] = $field['field_569a597e95338'];
$creds['remember'] = false;
$user = wp_signon( $creds, false );
$logged = get_user_by( 'email', $field['field_569a597e95338'] );
$logged = $logged->ID;
wp_redirect( site_url('/ad?id='. $field['field_569a597e95338'] .'&author_id='. $user_id ) ); exit;
}
//return $user_id;
}
break;
case 'advert':
$title = $field['field_569b032a73af9'];
$postname = sanitize_title($field['field_569b032a73af9']);
//Tratamento das Cidades como Taxonomias
$exist_state = term_exists( $field['field_569b07ac73afc'], 'estado_cidade' );
if( $exist_state == 0 && $exist_state == null){
$state = array(
'description'=> 'Encontre anuncios em '. $field['field_569b07ac73afc'] ,
'slug' => sanitize_title($field['field_569b07ac73afc']),
//'parent'=> $parent_term_id
);
$state_save = wp_insert_term($field['field_569b07ac73afc'], 'estado_cidade', $state );
$state_save = $state_save['term_id'];
}else{
$state_save = get_term_by('id', $field['field_569b07ac73afc'], 'estado_cidade' );
}
$exist_city = term_exists( $field['field_569b07c873afd'], 'estado_cidade' );
if($exist_city == 0 && $exist_city == null){
$cidade = array(
'description'=> 'O ADVirtual oferece diversos anuncios em '. $field['field_569b07c873afd'] ,
'slug' => sanitize_title($field['field_569b07c873afd']),
'parent'=> $estado_save
);
$city_save = wp_insert_term($field['field_569b07c873afd'], 'estado_cidade', $cidade );
$city_save = $city_save['term_id'];
}else {
$city_save = get_term_by('id', $field['field_569b07c873afd'], 'estado_cidade' );
}
$taxcidade = array(
'estado_cidade' => array( $city_save )
);
$post = array(
'ID' => $post_id,
'post_type' => 'advert',
'post_status' => 'draft',
'post_author' => $logged->ID,
'post_title' => $title,
'post_name' => $postname,
'tax_input' => $taxcidade,
);
// insert the post
$post_id = wp_insert_post( $post );
return $post_id;
wp_redirect( site_url('/ad?edit_ad='.$post_id.'&email='. $field['field_569a597e95338'] .'&author_id='. $user_id ) ); exit;
// $to = $field['field_565b0d414e11f'];
// $subject = "AdVirtual";
// $message = "Você cadastrou o anuncio" . $field['field_565a79b776849'] ;
// $headers[] = "From: Sérgio <[email protected]>";
// $headers[] = "Reply-To: no-reply <[email protected]>";
// $headers[] = "Content-type: text/html; charset=UTF-8";
// wp_mail( $to, $subject, $message, $headers );
break;
default:
echo "<script> alert('ERRO - Nova CTP - Entre em contato com o suporte urgente.'); </script>";
break;
}
}
}
add_filter('acf/pre_save_post' , 'salvar', 10, 1 );
The topic ‘Cannot pass through tax_input in ACF frontend form’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.