I have discovered that
$context['posts'] = Timber::get_posts('post_type=any');
//or
$context['posts'] = Timber::get_posts('post_type=test');
does not work for taxonomy archives. This way WP outputs all posts I have without filtering them for the taxonomy.
So in my case only this code works:
function test__pre_get_posts( $query ) {
if( !( is_post_type_archive() || is_admin() ) ) {
$query->set( 'post_type',
array(
'post', 'page', 'nav_menu_item', // Keep default types
'test-post-type',
'test-post-type-2'
)
);
}
}
add_action( 'pre_get_posts', 'test__pre_get_posts' );
NB! To preserve pages and menus to be shown post
, page
, nav_menu_item
types have to be included.