<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	
	>
<channel>
	<title>
	Comments on: Passing variables to get_template_part() in WordPress	</title>
	<atom:link href="https://keithdevon.com/passing-variables-to-get_template_part-in-wordpress/feed/" rel="self" type="application/rss+xml" />
	<link>https://keithdevon.com/passing-variables-to-get_template_part-in-wordpress/</link>
	<description>UK-based WordPress developer</description>
	<lastBuildDate>Sun, 06 Nov 2016 11:25:08 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.0.3</generator>
	<item>
		<title>
		By: Rob		</title>
		<link>https://keithdevon.com/passing-variables-to-get_template_part-in-wordpress/#comment-111285</link>

		<dc:creator><![CDATA[Rob]]></dc:creator>
		<pubDate>Sun, 06 Nov 2016 11:25:08 +0000</pubDate>
		<guid isPermaLink="false">http://keithdevon.wpengine.com/?p=1041#comment-111285</guid>

					<description><![CDATA[Why not just include the file in the first place rather than using get_template_part() ?

That way it&#039;s aware of the variables from file that includes it.

Not Wordpress standard practice (but then you are still using include in the template part anyway) but seems a lot more sensible than loading a template part and then loading the file that included it again. Infinitely loading files within themselves could lead to a lot of issues. At least consider using include_once instead of include.]]></description>
			<content:encoded><![CDATA[<p>Why not just include the file in the first place rather than using get_template_part() ?</p>
<p>That way it&#8217;s aware of the variables from file that includes it.</p>
<p>Not WordPress standard practice (but then you are still using include in the template part anyway) but seems a lot more sensible than loading a template part and then loading the file that included it again. Infinitely loading files within themselves could lead to a lot of issues. At least consider using include_once instead of include.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Christos		</title>
		<link>https://keithdevon.com/passing-variables-to-get_template_part-in-wordpress/#comment-110459</link>

		<dc:creator><![CDATA[Christos]]></dc:creator>
		<pubDate>Tue, 27 Sep 2016 17:08:57 +0000</pubDate>
		<guid isPermaLink="false">http://keithdevon.wpengine.com/?p=1041#comment-110459</guid>

					<description><![CDATA[You may easily pass variables to a template part, using the set_query_var / get_query_var functions, which are wrapper functions for the identically named WP_Query class methods.

SET THE VARIABLES:

    $options = array( &#039;option1&#039; =&#062; &#039;value1&#039;, &#039;option2&#039; =&#062; &#039;value2&#039; );
    set_query_var( &#039;my_options&#039;, $options );
    get_template_part( &#039;templates/example/part&#039; );

RETRIEVE THE VARIABLES IN TEMPLATE PART

    $options = get_query_var( &#039;my_options&#039; );
    if ( is_array( $options ) ) { extract($options); } 
    echo &#039;This is my option 1 value: &#039;. $option1 .&#039;&#039;;
    echo &#039;This is my option 2 value: &#039;. $option2;

...and just my two cents for theme authors. I think that the locate_template function suggested in this article is not the expected choice to include a template part. You might get the same result using it, nevertheless it does not provide the extra do_action trigger that get_template_part does...and some plugins might rely on it. In addition, using an include() function for your template parts will produce several alert notices on several quality review tools ( such as the Theme Check plugin ).]]></description>
			<content:encoded><![CDATA[<p>You may easily pass variables to a template part, using the set_query_var / get_query_var functions, which are wrapper functions for the identically named WP_Query class methods.</p>
<p>SET THE VARIABLES:</p>
<p>    $options = array( &#8216;option1&#8217; =&gt; &#8216;value1&#8217;, &#8216;option2&#8217; =&gt; &#8216;value2&#8217; );<br />
    set_query_var( &#8216;my_options&#8217;, $options );<br />
    get_template_part( &#8216;templates/example/part&#8217; );</p>
<p>RETRIEVE THE VARIABLES IN TEMPLATE PART</p>
<p>    $options = get_query_var( &#8216;my_options&#8217; );<br />
    if ( is_array( $options ) ) { extract($options); }<br />
    echo &#8216;This is my option 1 value: &#8216;. $option1 .&#8221;;<br />
    echo &#8216;This is my option 2 value: &#8216;. $option2;</p>
<p>&#8230;and just my two cents for theme authors. I think that the locate_template function suggested in this article is not the expected choice to include a template part. You might get the same result using it, nevertheless it does not provide the extra do_action trigger that get_template_part does&#8230;and some plugins might rely on it. In addition, using an include() function for your template parts will produce several alert notices on several quality review tools ( such as the Theme Check plugin ).</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: manu		</title>
		<link>https://keithdevon.com/passing-variables-to-get_template_part-in-wordpress/#comment-110336</link>

		<dc:creator><![CDATA[manu]]></dc:creator>
		<pubDate>Thu, 22 Sep 2016 09:48:23 +0000</pubDate>
		<guid isPermaLink="false">http://keithdevon.wpengine.com/?p=1041#comment-110336</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://keithdevon.com/passing-variables-to-get_template_part-in-wordpress/#comment-100459&quot;&gt;Russy&lt;/a&gt;.

Thank you. I think this is a better solution that the one provided by this article.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://keithdevon.com/passing-variables-to-get_template_part-in-wordpress/#comment-100459">Russy</a>.</p>
<p>Thank you. I think this is a better solution that the one provided by this article.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Passing variables to get_template_part - JolekPress		</title>
		<link>https://keithdevon.com/passing-variables-to-get_template_part-in-wordpress/#comment-110172</link>

		<dc:creator><![CDATA[Passing variables to get_template_part - JolekPress]]></dc:creator>
		<pubDate>Sun, 11 Sep 2016 22:05:17 +0000</pubDate>
		<guid isPermaLink="false">http://keithdevon.wpengine.com/?p=1041#comment-110172</guid>

					<description><![CDATA[[&#8230;] course! One alternative is to use something like the following, as pointed out by Keith Devon, instead of [&#8230;]]]></description>
			<content:encoded><![CDATA[<p>[&#8230;] course! One alternative is to use something like the following, as pointed out by Keith Devon, instead of [&#8230;]</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Maxime CULEA		</title>
		<link>https://keithdevon.com/passing-variables-to-get_template_part-in-wordpress/#comment-109892</link>

		<dc:creator><![CDATA[Maxime CULEA]]></dc:creator>
		<pubDate>Thu, 18 Aug 2016 23:44:36 +0000</pubDate>
		<guid isPermaLink="false">http://keithdevon.wpengine.com/?p=1041#comment-109892</guid>

					<description><![CDATA[Hi,
In my company we have managed to handle this with a custom class : https://github.com/BeAPI/bea-template-vars
Working like a charm !]]></description>
			<content:encoded><![CDATA[<p>Hi,<br />
In my company we have managed to handle this with a custom class : <a href="https://github.com/BeAPI/bea-template-vars" rel="nofollow ugc">https://github.com/BeAPI/bea-template-vars</a><br />
Working like a charm !</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: ONLYPS		</title>
		<link>https://keithdevon.com/passing-variables-to-get_template_part-in-wordpress/#comment-109858</link>

		<dc:creator><![CDATA[ONLYPS]]></dc:creator>
		<pubDate>Sun, 14 Aug 2016 11:54:21 +0000</pubDate>
		<guid isPermaLink="false">http://keithdevon.wpengine.com/?p=1041#comment-109858</guid>

					<description><![CDATA[just user 
in templte file $r = &quot;hi&quot;;

in template part:
 global $r;
 echo $r;
it will work fine]]></description>
			<content:encoded><![CDATA[<p>just user<br />
in templte file $r = &#8220;hi&#8221;;</p>
<p>in template part:<br />
 global $r;<br />
 echo $r;<br />
it will work fine</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Heitor		</title>
		<link>https://keithdevon.com/passing-variables-to-get_template_part-in-wordpress/#comment-109822</link>

		<dc:creator><![CDATA[Heitor]]></dc:creator>
		<pubDate>Wed, 10 Aug 2016 17:57:28 +0000</pubDate>
		<guid isPermaLink="false">http://keithdevon.wpengine.com/?p=1041#comment-109822</guid>

					<description><![CDATA[Thaaanks]]></description>
			<content:encoded><![CDATA[<p>Thaaanks</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Mairum		</title>
		<link>https://keithdevon.com/passing-variables-to-get_template_part-in-wordpress/#comment-109700</link>

		<dc:creator><![CDATA[Mairum]]></dc:creator>
		<pubDate>Wed, 27 Jul 2016 15:55:47 +0000</pubDate>
		<guid isPermaLink="false">http://keithdevon.wpengine.com/?p=1041#comment-109700</guid>

					<description><![CDATA[Thanks!]]></description>
			<content:encoded><![CDATA[<p>Thanks!</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: calvin		</title>
		<link>https://keithdevon.com/passing-variables-to-get_template_part-in-wordpress/#comment-109136</link>

		<dc:creator><![CDATA[calvin]]></dc:creator>
		<pubDate>Fri, 10 Jun 2016 12:25:53 +0000</pubDate>
		<guid isPermaLink="false">http://keithdevon.wpengine.com/?p=1041#comment-109136</guid>

					<description><![CDATA[Good call worth looking at the extra arguments in my initial rush I saw my content added twice ! as I was using it with the load and then including it as well. So working for me is..include(locate_template(&#039;template-parts/tray.php&#039;,false)); if false isn&#039;t set then it does the include twice and crucially the first time the var isn&#039;t available.]]></description>
			<content:encoded><![CDATA[<p>Good call worth looking at the extra arguments in my initial rush I saw my content added twice ! as I was using it with the load and then including it as well. So working for me is..include(locate_template(&#8216;template-parts/tray.php&#8217;,false)); if false isn&#8217;t set then it does the include twice and crucially the first time the var isn&#8217;t available.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Philipp		</title>
		<link>https://keithdevon.com/passing-variables-to-get_template_part-in-wordpress/#comment-101369</link>

		<dc:creator><![CDATA[Philipp]]></dc:creator>
		<pubDate>Wed, 14 Oct 2015 12:23:22 +0000</pubDate>
		<guid isPermaLink="false">http://keithdevon.wpengine.com/?p=1041#comment-101369</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://keithdevon.com/passing-variables-to-get_template_part-in-wordpress/#comment-95191&quot;&gt;Herus&lt;/a&gt;.

This is really the way to do it properly.
Don&#039;t use `include()`!

To get the variable, use get_query_var().]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://keithdevon.com/passing-variables-to-get_template_part-in-wordpress/#comment-95191">Herus</a>.</p>
<p>This is really the way to do it properly.<br />
Don&#8217;t use `include()`!</p>
<p>To get the variable, use get_query_var().</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
