Home › Forums › Front-end Issues › group field in frontend page › Reply To: group field in frontend page
How is the post created?
/*
* Agregar entrada personalizada "clientes" cuando se registra un nuevo usuario
*/
add_action( 'user_register', 'agregar_cp_clientes_usuario', 10, 1 );
function agregar_cp_clientes_usuario( $user_id ) {
// Get user info
$user_info = get_userdata( $user_id );
$user_roles = $user_info->roles;
// New code added
$this_user_role = implode(', ', $user_roles );
if ($this_user_role == 'cliente') {
// Create a new post
$user_post = array(
'post_title' => $user_info->user_nicename,
'post_author' => $user_info->ID,
'post_status' => 'publish', // <- here is to publish
'post_type' => 'clientes', // <- change to your cpt
);
// Insert the post into the database
$post_id = wp_insert_post( $user_post );
}
}
What is it that causes the user and the post that is automatically created related to each other?
They are related by the author of the post.
That is, the post is added automatically, when a new user registers.
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.