As I already mentioned in my comments, you must use pre_get_posts
to add custom post types to archive pages.
One thing you must keep in mind here though, you have two archive pages here, archive.php and archive-event.php, so is_archive()
is going to return true on both, which will alter both pages. You will need to exclude archive-event.php from your function. To do this, you'll need to make use of is_post_type_archive()
to check and exclude that specific page
For all the possible parameters you can use with pre_get_posts
, go have a look at WP_Query
function cpt_in_archive($query) {
if ( !is_admin() && $query->is_main_query() && $query->is_archive() && $query->!is_post_type_archive( 'event' )) {
$query->set( 'post_type', array( 'post', 'event' ) );
$query->set( 'orderby', 'date' );
}
}
add_action( 'pre_get_posts' , 'cpt_in_archive' );
pre_get_posts
to addpost
andevent
types to archive pagesarchive.php
file.