Support

Account

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.