For which reasons can get_template_part's $args fail to work? (WP 5.8.1 - PHP 7.4.23)

I'm a big fan of the introduction of the $args parameter in get_template_part() since WP 5.5... or rather I would be, since I can't make it work and must still rely on [set|get]_query_var().

The call to get_template_part() is set in an archive template, like archive-whatever.php and goes like this:

$args = array( 'my_var' = 'my_value' );
get_template_part( 'content', 'template-to-get', $args );

Then, as seen in every single example I've found, in content-template-to-get.php I do as follows:

if ( $args['my_var'] == 'my_value' ) {
    // do stuff
}

But the stuff never gets done.

Which can be the possible reasons? As already stated in the title, WP version is 5.8.1 and PHP version is 7.4.23

Tahnks!

Topic get-template-part Wordpress

Category Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.