WordPress: Agregar CTP a tag.php

6 abril 2020


Descripción

Por default los CPT no se muestran entag.php, este código hace que wordpress los identifique.

Referencia

https://wordpress.stackexchange.com/questions/28145/tag-php-doesnt-work-with-tags-on-a-custom-post-type-post

Lenguaje del código

HTML – WordPress

// Agregar a function.php para que los CPT aparezcan en los tags
function wpse28145_add_custom_types( $query ) {
    if( is_tag() && $query->is_main_query() ) {

        // this gets all post types:
        $post_types = get_post_types();

        // alternately, you can add just specific post types using this line instead of the above:
        // $post_types = array( 'post', 'your_custom_type' );

        $query->set( 'post_type', $post_types );
    }
}
add_filter( 'pre_get_posts', 'wpse28145_add_custom_types' );