valdisg
valdisg

Reputation: 13

how to display custom post type in archive.php?

I created custom post type with general categories (for default posts and custom posts the same categories) through the Custom Post Type UI plugin.

How to make on the category page so that, in addition to defaulted posts, custom posts for the same category are also displayed? Thanks

Upvotes: 1

Views: 305

Answers (1)

Stefano Pascazi
Stefano Pascazi

Reputation: 389

Create a function like this:

add_filter( 'pre_get_posts', 'my_get_posts' );

function my_get_posts( $query ) {

    if ( (is_category() or is_archive() ) && $query->is_main_query() )
        $query->set( 'post_type', array( 'post', 'your_post_type' ) );

    return $query;
}

Upvotes: 1

Related Questions