Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

264
Vistas
¿Cómo muestro el título de la publicación personalizada como "first_name last_name"?

Creé un sitio en el que los atletas pueden registrarse y crear su propia página de perfil con plantilla. Al registrarme, creo automáticamente una publicación personalizada (su perfil) y configuro al usuario como el autor de esa publicación.

Sin embargo, por mi vida no puedo establecer el título de la publicación como el nombre y apellido del usuario (ahora autor). Por ejemplo, si John Smith se registra, me gustaría que el título de la publicación diga John Smith y que el slug se convierta en atleta/john.smith .

He usado $user_info->nickname por ahora, pero esto hace que tanto el título como el slug se lea como john.smith

Este es el código que estoy usando, cualquier sugerencia sería muy apreciada:

 add_action( 'user_register', 'wpse_216921_company_cpt', 10, 1 ); function wpse_216921_company_cpt( $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 == 'author') { // Create a new post $user_post = array( 'post_title' => $user_info->nickname, 'post_status' => 'publish', // <- here is to publish 'post_type' => 'athlete', // <- change to your cpt 'post_author' => $user_info->ID ); // Insert the post into the database $post_id = wp_insert_post( $user_post ); } }
over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

También debe usar post_name para slug (john.smith) y first_name, last name para el título de la publicación como este:

 add_action( 'user_register', 'wpse_216921_company_cpt', 20, 1 ); function wpse_216921_company_cpt( $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 == 'author') { $post_title = $user_info->first_name.' '.$user_info->last_name; $post_title = trim(ucwords($post_title)); $post_slug = preg_replace('/\s+/', '.', $post_title); // Create a new post $user_post = array( 'post_title' => $post_title, //$user_info->display_name, 'post_name' => $post_slug, 'post_status' => 'publish', // <- here is to publish 'post_type' => 'athlete', // <- change to your cpt 'post_author' => $user_info->ID ); // Insert the post into the database $post_id = wp_insert_post( $user_post ); } }
over 4 years ago · Santiago Trujillo Denunciar

0

Puede usar el nombre y el apellido como se muestra a continuación:

 add_action( 'user_register', 'wpse_216921_company_cpt', 10, 1 ); function wpse_216921_company_cpt( $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 ); $first_name = $user_info->first_name; $last_name = $user_info->last_name; if ($this_user_role == 'author') { // Create a new post $user_post = array( 'post_title' => $first_name . ' ' . $last_name, 'post_status' => 'publish', // <- here is to publish 'post_type' => 'athlete', // <- change to your cpt 'post_author' => $user_info->ID ); // Insert the post into the database $post_id = wp_insert_post( $user_post ); } }

No probado, pero debería funcionar.

over 4 years ago · Santiago Trujillo Denunciar

0

Gracias por la ayuda chicos. Resultó ser un problema de Ultimate Member y necesitaba usar el Hook de UM um_registration_complete.

La solución final que funcionó es la siguiente:

 //Create Custom Post Type on registration add_action( 'um_registration_complete', 'wpse_216921_company_cpt', 10, 1 ); function wpse_216921_company_cpt( $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 == 'author') { $post_title = $user_info->first_name.' '.$user_info->last_name; $post_title = trim(ucwords($post_title)); $post_slug = preg_replace('/\s+/', '.', $post_title); // Create a new post $user_post = array( 'post_title' => $post_title, //$user_info->display_name, 'post_name' => $post_slug, 'post_status' => 'publish', // <- here is to publish 'post_type' => 'athlete', // <- change to your cpt 'post_author' => $user_info->ID ); // Insert the post into the database $post_id = wp_insert_post( $user_post ); } }
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda