You have a couple mistakes in your code:
is_archive()does not accept any parameters
is_archive()does not accept any parameters. If you want to check if this is the archive of a custom post type, useis_post_type_archive( $post_type )
-
Instead of using
include( plugin_dir_path( __FILE__ ) . 'my-template.php');, usedirname( __FILE__ ) . 'my-template.php'; -
Single templates has its own filter,
single_template, so split your function so that you have yourtemplate_includefor the archive page separately
Try something like this
add_filter('template_include', function ( $template ) {
if( is_post_type_archive( 'hhavideo' ) ){
$template = dirname( __FILE__ ) . '/templates/archive-hhavideo.php';
}
return $template;
}, PHP_INT_MAX, 2 );
add_filter( 'single_template', function ($single_template) {
if ( is_singular( 'hhavideo' ) ) {
$single_template = dirname( __FILE__ ) . '/templates/single-hhavideo.php';
}
return $single_template;
}, PHP_INT_MAX, 2 );