Can not filter the archive template in pre_get_post

Hi all!

using sage10 + created a custom archive blade for my custom post type I try to include the right archive template in pre_get_posts

Here is my code from setup.php

add_action('pre_get_posts', function ($query) {
    if ($query->is_main_query() && !is_admin() && is_post_type_archive('news')) {
        $query->set( 'post_type', [ 'news', 'press' ] );
        $query->set('posts_per_page', 3);


        add_filter( 'template_include', function ($template) {
            if ( is_post_type_archive( ['news' ] ) ) {
                $newsTemplate = locate_template( ['archive-news.php' ] );
               $newsTemplate = locate_template( ['archive-news.blade.php' ] );
                dd($newsTemplate);
                if ( '' != $newsTemplate ) {
                    return $newsTemplate;
                }
            }
            return $template;
        }, 99 );

        return $query;
    }
});

The template is empty. What I do wrong in this case?

1 Like

Try locate_template( app(‘sage.finder’)->locate(‘archive-news’) )

Via Load a specific blade template for custom URL structure with WP rewrite