Crear Custom Post Types para Genesis Framework

C贸mo crear un Custom Post Type lo puedes ver en este  post, pero si trabajamos con Genesis Framework, tendr铆amos que a帽adir unas caracter铆sticas para que el nuevo CPT tenga todas las opciones, y virtudes, que da Genesis. Para ello hay que completar supports.

Para los que no quer谩is teclear c贸digo, recomiendo este plugin: Custom post type UI

Los supports聽de una instalaci贸n de Wp sin Gensis Framework:

'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' ),

Veamos pues, c贸mo podemos completarlo:

'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments', 'genesis-cpt-archives-settings', 'genesis-seo', 'genesis-scripts', 'genesis-layouts', 'genesis-rel-autor',),

C贸mo a帽adir las funciones de Genesis a un Custom Post Type

El c贸digo se tendr谩 que a帽adir en el function.php del child-theme. En este caso, al ser Genesis se puede usar el plugin Extender Custom o crear el directorio mu-plugins dentro de wp-content y, ah铆 crear nombre-de-nuestro-cpt.php donde a帽adiremos el c贸digo siguiente:

Si es un CPT de tercero valdr铆a con a帽adir lo siguiente: add_post_type_support( ‘nombre_del_cpt’, array (‘genesis-cpt-archives-settings’, ‘genesis-seo’, ‘genesis-scripts’, ‘genesis-layouts’, ‘genesis-rel-autor’) );

Ejemplo CPT propio para Genesis

<?php
/*
Plugin Name: CPT para Noticias
Plugin URI: https://yanez.pro/
Description: Crear un CPT para un contenido tipo noticia.
Author: JYY
Author URI: https://yanez.pro/
Version: 1.0.0
Text Domain: ypro-cpt-noticia
Domain Path: /
*/


/*
This code is a plugin to create a Custom Post Type in WordPress, it can be used with any WordPress theme.
The action initialises the function below it.
This example uses the term 鈥楴oticias鈥 as its name, a search and replace will allow any name to be used, making sure plural and singular versions of the name are replaced.
Also replace the name in 鈥榬ewrite鈥 and in the 鈥榬egister_post_type鈥 function.
For non-Genesis themes the 鈥榞enesis-cpt-archives-settings鈥 can be removed from the supports array.
To activate this as a plugin just add to wp-contents/plugins and activate in Dashboard


This doesn鈥檛 use all the labels and arguments possible but includes the main ones, you can see more here 鈥 https://codex.wordpress.org/Function_Reference/register_post_type
*/


add_action( 鈥榠nit鈥, 鈥榶pro_noticias__create_custom_post_type鈥 );


function ypro_noticias__create_custom_post_type() {


    $labels = array(
        鈥榥ame鈥               => __( 鈥楴oticia鈥 ),
        鈥榮ingular_name鈥      => __( 鈥楴oticia鈥 ),
        鈥榓ll_items鈥          => __( 鈥楾odas las Noticias鈥 ),
        鈥榓dd_new鈥            => _x( 鈥楢帽adir Noticia鈥, 鈥楴oticias鈥 ),
        鈥榓dd_new_item鈥       => __( 鈥楢帽adir Noticia鈥 ),
        鈥榚dit_item鈥          => __( 鈥楨ditar Noticia鈥 ),
        鈥榥ew_item鈥           => __( 鈥楴ueva Noticia鈥 ),
        鈥榲iew_item鈥          => __( 鈥榁er Noticia鈥 ),
        鈥榮earch_items鈥       => __( 鈥楤uscar en Noticias鈥 ),
        鈥榥ot_found鈥          => __( 鈥楴o se han encontrado Noticias鈥 ),
        鈥榥ot_found_in_trash鈥 => __( 鈥楴o se han encontrado Noticias eliminadas鈥 ),
        鈥榩arent_item_colon鈥  => 禄
    );
    $args = array(
        鈥榣abels鈥             => $labels,
        鈥榩ublic鈥             => true,
        鈥榟as_archive鈥        => true,
        鈥榤enu_icon鈥          => 鈥榙ashicons-admin-users鈥, //pick one here ~> https://developer.wordpress.org/resource/dashicons/
        鈥榬ewrite鈥            => array( 鈥榮lug鈥 => 鈥榥oticia鈥 ),
        鈥榯axonomies鈥         => array( 鈥榗ategory鈥, 鈥榩ost_tag鈥 ),
        鈥榪uery_var鈥          => true,
        鈥榤enu_position鈥      => 5,
        鈥榮upports鈥           => array( 鈥榞enesis-cpt-archives-settings鈥, 鈥榯humbnail鈥 , 鈥榗ustom-fields鈥, 鈥榚xcerpt鈥, 鈥榗omments鈥, 鈥榯itle鈥, 鈥榚ditor鈥)
    );
    register_post_type( 鈥榥oticia鈥, $args );
}


// flush the permalinks 鈥 ref 鈥 https://codex.wordpress.org/Function_Reference/register_post_type#Flushing_Rewrite_on_Activation


function ypro_noticias__my_rewrite_flush() {
    // First, we 芦add禄 the custom post type via the above written function.
    // Note: 芦add禄 is written with quotes, as CPTs don鈥檛 get added to the DB,
    // They are only referenced in the post_type column with a post entry,
    // when you add a post of this CPT.
    ypro_noticias__create_custom_post_type();


    // ATTENTION: This is *only* done during plugin activation hook in this example!
    // You should *NEVER EVER* do this on every page load!!
    flush_rewrite_rules();
}
register_activation_hook( __FILE__, 鈥榶pro_noticias__my_rewrite_flush鈥 );