I am looking on how to include variable only when needed into a partial which is loaded for every loop.
I have tried set_query_var which works good for including variable but seems like my usage of remove_query_var after doesn’t work properly. What am I missing? Documentation doesn’t say much although it has been added only recently (4.5.0 version)

<ul itemscope itemtype="http://schema.org/ItemList">
    // Set variable for partial
    $schema_markup = true; 
    set_query_var('schema_markup', $schema_markup);

    while ($query->have_posts())  :

    // Load partial view 


    // Remove variable so that it doesn't trigger when partials are called later in the page where microdata is not needed
    global $wp;

Starting code inside partials/loop/post-xs

<li <?php if(!empty($schema_markup)) echo 'itemprop="itemListElement" itemscope itemtype="http://schema.org/Article"'; ?>>

Read more here: How to set variable, pass it to a partial file and remove it after?


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Wordpress related questions and answers: