Habilitar Gutenberg en un tipo de entrada personalizada

30 dic 2018, 14:31:19
Vistas: 38.2K
Votos: 32

Tengo este tipo de entrada personalizada:

function create_posttype() {
  register_post_type( 'companies',
    array(
      'labels' => array(
        'name' => __( 'شرکتهای عضو' ),
        'singular_name' => __( 'شرکت' )
      ),
      'supports' => array('title', 'editor', 'custom-fields', 'excerpt', 'thumbnail'),
      'public' => true,
      'has_archive' => true,
      'rewrite' => array('slug' => 'companies'),
    )
  );
}
add_action( 'init', 'create_posttype' );

Que muestra el editor clásico en el área de administración de WordPress. Intenté reemplazar 'editor' con 'gutenberg' en el array de supports, lo cual no funciona. También agregué este código a mi función como se sugiere aquí:

add_filter('gutenberg_can_edit_post_type', 'prefix_disable_gutenberg');
function prefix_disable_gutenberg($current_status, $post_type)
{
    if ($post_type === 'companies') return true;
    return $current_status;
}

¿Cómo puedo tener un editor Gutenberg en mi tipo de entrada personalizada?

1
Comentarios

este artículo puede ayudarte - https://webomnizz.com/how-to-enable-gutenberg-editor-with-custom-post-type/

jogesh_pi jogesh_pi
7 sept 2020 10:26:05
Todas las respuestas a la pregunta 2
2
72

Para que Gutenberg funcione en un Custom Post Type (Tipo de Entrada Personalizado) necesitas habilitar tanto el editor en supports (que ya tienes) como show_in_rest. Así que añade 'show_in_rest' => true, al array de argumentos de registro de tu entrada.

30 dic 2018 14:40:18
Comentarios

Me alegra que funcione, de nada.

Alvaro Alvaro
30 dic 2018 14:50:12

Funciona bien, gracias

Ferrmolina Ferrmolina
9 may 2020 16:37:38
0
10

Comienza registrando un tipo personalizado en Gutenberg para WordPress. El proceso es bastante sencillo e implica añadir el siguiente fragmento de código.

/* Registrar CPT personalizado para Gutenberg en WordPress */
function cw_post_type() {

    register_post_type( 'portfolio',
        // Opciones del CPT en WordPress
        array(
            'labels' => array(
                'name' => __( 'Portafolio' ),
                'singular_name' => __( 'Portafolio' )
            ),
            'has_archive' => true,
            'public' => true,
            'rewrite' => array('slug' => 'portafolio'),
            'show_in_rest' => true,
            'supports' => array('editor')
        )
    );
}

add_action( 'init', 'cw_post_type' );

Añade la clave show_in_rest y configúrala como true en tu tipo de entrada personalizado.

'show_in_rest' => true,
   'supports' => array('editor')

Como puedes ver, el fragmento de código anterior simplemente establece el parámetro 'show_in_rest' como 'TRUE'. Después de este paso, cuando crees o edites un tipo de entrada personalizado, verás que el editor de Gutenberg estará visible y habilitado.

Todos los pasos y consultas se discuten en detalle en https://www.cloudways.com/blog/gutenberg-wordpress-custom-post-type/

13 mar 2019 11:33:04