Custom Empty Results page for my Custom Post Type

The problem is that when there are no posts in the search query, WordPress doesn’t set the post type in the global WP_Query (get_post_type() relies on that). So, when there are no search results, get_post_type() will return false and all of your custom template logic will be skipped.

What you can do is also consider looking at the request parameters and check if the post type is there and the right value. Also please note that you are not handling 404 for your custom post type (is_404()). Here is how your function would look with both cases taken into account:

function wikicon_include_templates( $template_path ) {
    if ( 'wikicon_recurso' === get_post_type() || 'wikicon_recurso' === get_query_var('post_type') ) {
        if ( is_singular() ) {
            $template_path = plugin_dir_path( __FILE__ ) . '/single-wikicon_recurso.php';
        }
        elseif ( is_search() ) {
            $template_path = plugin_dir_path( __FILE__ ) . '/search-wikicon_recurso.php';
        }
        elseif ( is_archive() || is_404() ) {
            $template_path = plugin_dir_path( __FILE__ ) . '/archive-wikicon_recurso.php';
        }
    }

    return $template_path;
}
add_filter( 'template_include', 'wikicon_include_templates', 999, 1 );

A couple of tips:

  • I added a prefix to your function as it is good practice to do so (include_template_function is quite a common name);
  • there is no point in including _function in your function name 🙂 ;
  • if want to make sure that no other plugin or theme will filter the templates and override your logic (and have you banging your head against the wall wondering why it’s not working), you should use a big priority number, like 999, to make sure your logic executes last.

Let me know if this does the trick.