<?xml version="1.0" encoding="UTF-8"?><!-- generator="bbPress" -->

<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
>

<channel>
<title>WordPress &#8250; Support Topic: passing current single_tag_title as variable into new wp_query</title>
<link>http://wordpress.org/support/</link>
<description>WordPress &#8250; Support Topic: passing current single_tag_title as variable into new wp_query</description>
<language>en</language>
<pubDate>Tue, 24 Nov 2009 02:25:00 +0000</pubDate>

<item>
<title>mbuhnici on "passing current single_tag_title as variable into new wp_query"</title>
<link>http://wordpress.org/support/topic/247918#post-1070773</link>
<pubDate>Mon, 11 May 2009 13:50:32 +0000</pubDate>
<dc:creator>mbuhnici</dc:creator>
<guid isPermaLink="false">1070773@http://wordpress.org/support/</guid>
<description>&#60;p&#62;I found the solution myself. Here: &#60;a href=&#34;http://www.3mind.at/2009/05/06/code-highlighting/&#34; rel=&#34;nofollow&#34;&#62;http://www.3mind.at/2009/05/06/code-highlighting/&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;Backup the current $post object at the beginning of our code and copy it back at the end, where you also call the built-in function wp_reset_query().&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;&#38;lt;?php  //for use in the loop, list 5 post titles related to first tag on current post&#60;br /&#62;
  $backup = $post;  // backup the current object&#60;br /&#62;
  $tags = wp_get_post_tags($post-&#38;gt;ID);&#60;br /&#62;
  $tagIDs = array();&#60;br /&#62;
  if ($tags) {&#60;br /&#62;
    $tagcount = count($tags);&#60;br /&#62;
    for ($i = 0; $i &#38;lt; $tagcount; $i++) {&#60;br /&#62;
      $tagIDs[$i] = $tags[$i]-&#38;gt;term_id;&#60;br /&#62;
    }&#60;br /&#62;
    $args=array(&#60;br /&#62;
      'tag__in' =&#38;gt; $tagIDs,&#60;br /&#62;
      'post__not_in' =&#38;gt; array($post-&#38;gt;ID),&#60;br /&#62;
      'showposts'=&#38;gt;5,&#60;br /&#62;
      'caller_get_posts'=&#38;gt;1&#60;br /&#62;
    );&#60;br /&#62;
    $my_query = new WP_Query($args);&#60;br /&#62;
    if( $my_query-&#38;gt;have_posts() ) {&#60;br /&#62;
      while ($my_query-&#38;gt;have_posts()) : $my_query-&#38;gt;the_post(); ?&#38;gt;&#60;br /&#62;
        &#38;lt;h3&#38;gt;&#60;a&#62;&#34; rel=&#34;bookmark&#34; title=&#34;&#38;lt;?php the_title(); ?&#38;gt;&#34;&#38;gt;&#38;lt;?php the_title(); ?&#38;gt;&#60;/a&#62;&#38;lt;/h3&#38;gt;&#60;br /&#62;
      &#38;lt;?php endwhile;&#60;br /&#62;
    }&#60;br /&#62;
  }&#60;br /&#62;
  $post = $backup;  // copy it back&#60;br /&#62;
  wp_reset_query(); // to use the original query again&#60;br /&#62;
?&#38;gt;&#60;/p&#62;&#60;/blockquote&#62;</description>
</item>
<item>
<title>mbuhnici on "passing current single_tag_title as variable into new wp_query"</title>
<link>http://wordpress.org/support/topic/247918#post-1070766</link>
<pubDate>Mon, 11 May 2009 13:41:15 +0000</pubDate>
<dc:creator>mbuhnici</dc:creator>
<guid isPermaLink="false">1070766@http://wordpress.org/support/</guid>
<description>&#60;p&#62;@MichaelH&#60;br /&#62;
I have the same problem with the code, the comments displayed come from the last post in the similar posts list. What can I do about it?
&#60;/p&#62;</description>
</item>
<item>
<title>foglub on "passing current single_tag_title as variable into new wp_query"</title>
<link>http://wordpress.org/support/topic/247918#post-1059197</link>
<pubDate>Tue, 28 Apr 2009 19:24:21 +0000</pubDate>
<dc:creator>foglub</dc:creator>
<guid isPermaLink="false">1059197@http://wordpress.org/support/</guid>
<description>&#60;p&#62;Hey Michael H,&#60;/p&#62;
&#60;p&#62;Is there any way to change the code you made from 'first tag' to display 5 posts related (randomly) to ALL of the current post's tags?&#60;/p&#62;
&#60;p&#62;Thanks!
&#60;/p&#62;</description>
</item>
<item>
<title>Hoboballan on "passing current single_tag_title as variable into new wp_query"</title>
<link>http://wordpress.org/support/topic/247918#post-1046911</link>
<pubDate>Wed, 15 Apr 2009 21:37:38 +0000</pubDate>
<dc:creator>Hoboballan</dc:creator>
<guid isPermaLink="false">1046911@http://wordpress.org/support/</guid>
<description>&#60;p&#62;Hi MichaelH,&#60;/p&#62;
&#60;p&#62;This code is great, but for some reason if there is a comment for the last relevant post, it puts that into comments section..?&#60;/p&#62;
&#60;p&#62;Is there something i'm missing here?
&#60;/p&#62;</description>
</item>
<item>
<title>wrosner on "passing current single_tag_title as variable into new wp_query"</title>
<link>http://wordpress.org/support/topic/247918#post-1041415</link>
<pubDate>Thu, 09 Apr 2009 14:29:12 +0000</pubDate>
<dc:creator>wrosner</dc:creator>
<guid isPermaLink="false">1041415@http://wordpress.org/support/</guid>
<description>&#60;p&#62;I have been looking high and low for an answer to my problem which is related to above.&#60;/p&#62;
&#60;p&#62;In my template I am displaying a page and wanting to show groups of related posts on the right.  Each group is a category and each post is also tagged with a keyword.  In this particular part of my site I am using the title of the page as the match for the keyword.  Example might be category of &#34;Quick Tips&#34; for tag equaling &#34;Foo&#34;.  I would want that post listed when on the &#34;Foo&#34; page.&#60;/p&#62;
&#60;p&#62;Here's the code.&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;&#38;lt;?php
			$args =&#38;quot;cat=80&#38;amp;amp;tag=&#38;quot;.$mypage_title.&#38;quot;&#38;amp;amp;showposts=5&#38;quot;;
			echo ($args);
			$recent = new WP_Query($args);

		if ($recent-&#38;gt;have_posts()) {
			?&#38;gt;&#38;lt;h4&#38;gt;Quick Tips&#38;lt;/h4&#38;gt;
			&#38;lt;ul&#38;gt;
			&#38;lt;?php
			while($recent-&#38;gt;have_posts()) : $recent-&#38;gt;the_post();
				//if (has_tag($mypage_title)) {
				if (get_post_meta($post-&#38;gt;ID, &#38;#39;flv&#38;#39;, true)) {
				?&#38;gt;
				&#38;lt;li&#38;gt;&#38;lt;a class=&#38;quot;sidebarnav1&#38;quot; href=&#38;quot;&#38;lt;?php the_permalink()?&#38;gt;&#38;quot;&#38;gt;&#38;lt;img width=&#38;quot;20&#38;quot; src=&#38;quot;/wordpress/wp-content/themes/revolution_business-10/_images/video2.jpeg&#38;quot;&#38;gt; &#38;lt;?php the_title(); ?&#38;gt;&#38;lt;/a&#38;gt;&#38;lt;/li&#38;gt;
				&#38;lt;?php }else{ ?&#38;gt;
				&#38;lt;li&#38;gt;&#38;lt;a class=&#38;quot;sidebarnav1&#38;quot; href=&#38;quot;&#38;lt;?php the_permalink()?&#38;gt;&#38;quot;&#38;gt;&#38;lt;?php the_title(); ?&#38;gt;&#38;lt;/a&#38;gt;&#38;lt;/li&#38;gt;

				&#38;lt;?php }//}
			endwhile; ?&#38;gt;
			&#38;lt;/ul&#38;gt;&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;When I use add the &#34;tag=????&#34; I stopped getting back any posts.  I have echo'd my $args and they do contain the page title.  I got page title using &#60;/p&#62;
&#60;p&#62;&#60;code&#62;$mypage_title = trim(wp_title(&#38;#39;&#38;#39;,false,&#38;#39;&#38;#39;));&#60;/code&#62;&#60;/p&#62;
&#60;p&#62;What am I doing wrong that combining category and tag won't work?  &#60;/p&#62;
&#60;p&#62;Thanks for any help!&#60;/p&#62;
&#60;p&#62;Wes
&#60;/p&#62;</description>
</item>
<item>
<title>ErnestoJustiniano.org on "passing current single_tag_title as variable into new wp_query"</title>
<link>http://wordpress.org/support/topic/247918#post-1025880</link>
<pubDate>Wed, 25 Mar 2009 07:33:32 +0000</pubDate>
<dc:creator>ErnestoJustiniano.org</dc:creator>
<guid isPermaLink="false">1025880@http://wordpress.org/support/</guid>
<description>&#60;p&#62;hi, can i request to you the same for Recent Post frome the same category? I am working with this code outside the loop (only category but goes with author too), &#60;strong&#62;but yours seem very better&#60;/strong&#62;.&#60;/p&#62;
&#60;p&#62;&#38;lt;?php&#60;/p&#62;
&#60;p&#62;  //Gets category and author info&#60;br /&#62;
  global $wp_query;&#60;br /&#62;
$cats = get_the_category();&#60;br /&#62;
  $postAuthor = $wp_query-&#38;gt;post-&#38;gt;post_author;&#60;br /&#62;
$tempQuery = $wp_query;&#60;br /&#62;
  $currentId = $post-&#38;gt;ID;&#60;/p&#62;
&#60;p&#62;// related author posts&#60;br /&#62;
  $newQuery = &#34;posts_per_page=5&#38;#38;author=&#34; . $authorPosts;&#60;br /&#62;
  query_posts( $newQuery );&#60;br /&#62;
$authorPosts = &#34;&#34;;&#60;br /&#62;
  $count = 0;&#60;br /&#62;
if (have_posts()) {&#60;br /&#62;
  while (have_posts()) {&#60;br /&#62;
  $count++;&#60;br /&#62;
  the_post();&#60;br /&#62;
  if( $count&#38;lt;4 &#38;#38;&#38;#38; $currentId!=$post-&#38;gt;ID) {&#60;br /&#62;
  $count++;&#60;br /&#62;
  $authorPosts .= '
&#60;li&#62;&#60;a href=&#34;' . get_permalink() . '&#34;&#62;' . the_title( &#34;&#34;, &#34;&#34;, false ) . '&#60;/a&#62;&#60;/li&#62;
';&#60;br /&#62;
  }&#60;br /&#62;
  }&#60;br /&#62;
  }&#60;/p&#62;
&#60;p&#62;// related category posts&#60;br /&#62;
  $catlist = &#34;&#34;;&#60;br /&#62;
  forEach( $cats as $c ) {&#60;br /&#62;
  if( $catlist != &#34;&#34; ) { $catlist .= &#34;,&#34;; }&#60;br /&#62;
  $catlist .= $c-&#38;gt;cat_ID;&#60;br /&#62;
  }&#60;br /&#62;
  $newQuery = &#34;posts_per_page=5&#38;#38;cat=&#34; . $catlist;&#60;br /&#62;
  query_posts( $newQuery );&#60;br /&#62;
$categoryPosts = &#34;&#34;;&#60;br /&#62;
  $count = 0;&#60;br /&#62;
if (have_posts()) {&#60;br /&#62;
  while (have_posts()) {&#60;br /&#62;
  the_post();&#60;br /&#62;
  if( $count&#38;lt;4 &#38;#38;&#38;#38; $currentId!=$post-&#38;gt;ID) {&#60;br /&#62;
  $count++;&#60;br /&#62;
  $categoryPosts .= '
&#60;li&#62;&#60;a href=&#34;' . get_permalink() . '&#34;&#62;' . the_title( &#34;&#34;, &#34;&#34;, false ) . '&#60;/a&#62;&#60;/li&#62;
';&#60;br /&#62;
  }&#60;br /&#62;
  }&#60;br /&#62;
  }&#60;br /&#62;
  $wp_query = $tempQuery;&#60;br /&#62;
  ?&#38;gt;&#60;br /&#62;
&#38;lt;?php while ($wp_query-&#38;gt;have_posts()) : $wp_query-&#38;gt;the_post(); ?&#38;gt;&#60;br /&#62;
	&#38;lt;h2&#38;gt;Ultimos art&#38;iacute;culos de la categor&#38;iacute;a: &#38;lt;?php the_category(', ');?&#38;gt;&#38;lt;/h2&#38;gt;&#60;/p&#62;
&#60;ul&#62;
&#60;li&#62;
&#38;lt;?php echo $categoryPosts; ?&#38;gt;
&#60;/li&#62;
&#60;/ul&#62;
&#60;p&#62;&#38;lt;?php endwhile;?&#38;gt;
&#60;/p&#62;</description>
</item>
<item>
<title>patcheta on "passing current single_tag_title as variable into new wp_query"</title>
<link>http://wordpress.org/support/topic/247918#post-1007483</link>
<pubDate>Fri, 06 Mar 2009 17:29:32 +0000</pubDate>
<dc:creator>patcheta</dc:creator>
<guid isPermaLink="false">1007483@http://wordpress.org/support/</guid>
<description>&#60;p&#62;You guys are awesome. Thanks so much!
&#60;/p&#62;</description>
</item>
<item>
<title>MichaelH on "passing current single_tag_title as variable into new wp_query"</title>
<link>http://wordpress.org/support/topic/247918#post-1001978</link>
<pubDate>Sun, 01 Mar 2009 16:20:45 +0000</pubDate>
<dc:creator>MichaelH</dc:creator>
<guid isPermaLink="false">1001978@http://wordpress.org/support/</guid>
<description>&#60;p&#62;@greenshady: well you've got a million other good ideas and code examples, Justin...&#60;/p&#62;
&#60;p&#62;patcheta:  saw something yesterday that should probably be changed/added at the end of the code there, adding the wp_reset_query so it doesn't blowup the_post in your regular loop.&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;&#38;lt;?php
//for use in the loop, list 5 post titles related to first tag on current post
$tags = wp_get_post_tags($post-&#38;gt;ID);
if ($tags) {
  echo &#38;#39;Related Posts&#38;#39;;
  $first_tag = $tags[0]-&#38;gt;term_id;
  $args=array(
    &#38;#39;tag__in&#38;#39; =&#38;gt; array($first_tag),
    &#38;#39;post__not_in&#38;#39; =&#38;gt; array($post-&#38;gt;ID),
    &#38;#39;showposts&#38;#39;=&#38;gt;5,
    &#38;#39;caller_get_posts&#38;#39;=&#38;gt;1
   );
  $my_query = new WP_Query($args);
  if( $my_query-&#38;gt;have_posts() ) {
    while ($my_query-&#38;gt;have_posts()) : $my_query-&#38;gt;the_post(); ?&#38;gt;
      &#38;lt;a href=&#38;quot;&#38;lt;?php the_permalink() ?&#38;gt;&#38;quot; rel=&#38;quot;bookmark&#38;quot; title=&#38;quot;Permanent Link to &#38;lt;?php the_title_attribute(); ?&#38;gt;&#38;quot;&#38;gt;&#38;lt;?php the_title(); ?&#38;gt;&#38;lt;/a&#38;gt;

      &#38;lt;?php
    endwhile;
  }
wp_reset_query();
}
?&#38;gt;&#60;/code&#62;&#60;/pre&#62;</description>
</item>
<item>
<title>greenshady on "passing current single_tag_title as variable into new wp_query"</title>
<link>http://wordpress.org/support/topic/247918#post-1001410</link>
<pubDate>Sat, 28 Feb 2009 21:47:19 +0000</pubDate>
<dc:creator>greenshady</dc:creator>
<guid isPermaLink="false">1001410@http://wordpress.org/support/</guid>
<description>&#60;p&#62;Ahh!  I just realized what I coded was for tag archive pages.  Where's my head at? :)
&#60;/p&#62;</description>
</item>
<item>
<title>MichaelH on "passing current single_tag_title as variable into new wp_query"</title>
<link>http://wordpress.org/support/topic/247918#post-1001174</link>
<pubDate>Sat, 28 Feb 2009 16:45:55 +0000</pubDate>
<dc:creator>MichaelH</dc:creator>
<guid isPermaLink="false">1001174@http://wordpress.org/support/</guid>
<description>&#60;p&#62;No, just coded that for you.
&#60;/p&#62;</description>
</item>
<item>
<title>patcheta on "passing current single_tag_title as variable into new wp_query"</title>
<link>http://wordpress.org/support/topic/247918#post-1001132</link>
<pubDate>Sat, 28 Feb 2009 16:00:41 +0000</pubDate>
<dc:creator>patcheta</dc:creator>
<guid isPermaLink="false">1001132@http://wordpress.org/support/</guid>
<description>&#60;p&#62;Thanks so much MichaelH, I can't tell you how much I appreciate your help. Was that information listed in a doc somewhere? If so I missed it. Please post the link if there is one. Thanks again.
&#60;/p&#62;</description>
</item>
<item>
<title>MichaelH on "passing current single_tag_title as variable into new wp_query"</title>
<link>http://wordpress.org/support/topic/247918#post-1001106</link>
<pubDate>Sat, 28 Feb 2009 15:13:31 +0000</pubDate>
<dc:creator>MichaelH</dc:creator>
<guid isPermaLink="false">1001106@http://wordpress.org/support/</guid>
<description>&#60;p&#62;This should work with the WordPress Default Theme's index.php:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;&#38;lt;?php
//for use in the loop, list 5 post titles related to first tag on current post
$tags = wp_get_post_tags($post-&#38;gt;ID);
if ($tags) {
  echo &#38;#39;Related Posts&#38;#39;;
  $first_tag = $tags[0]-&#38;gt;term_id;
  $args=array(
    &#38;#39;tag__in&#38;#39; =&#38;gt; array($first_tag),
    &#38;#39;post__not_in&#38;#39; =&#38;gt; array($post-&#38;gt;ID),
    &#38;#39;showposts&#38;#39;=&#38;gt;5,
    &#38;#39;caller_get_posts&#38;#39;=&#38;gt;1
   );
  $my_query = new WP_Query($args);
  if( $my_query-&#38;gt;have_posts() ) {
    while ($my_query-&#38;gt;have_posts()) : $my_query-&#38;gt;the_post(); ?&#38;gt;
      &#38;lt;p&#38;gt;&#38;lt;a href=&#38;quot;&#38;lt;?php the_permalink() ?&#38;gt;&#38;quot; rel=&#38;quot;bookmark&#38;quot; title=&#38;quot;Permanent Link to &#38;lt;?php the_title_attribute(); ?&#38;gt;&#38;quot;&#38;gt;&#38;lt;?php the_title(); ?&#38;gt;&#38;lt;/a&#38;gt;&#38;lt;/p&#38;gt;
      &#38;lt;?php
    endwhile;
  }
}
?&#38;gt;&#60;/code&#62;&#60;/pre&#62;</description>
</item>
<item>
<title>greenshady on "passing current single_tag_title as variable into new wp_query"</title>
<link>http://wordpress.org/support/topic/247918#post-1001000</link>
<pubDate>Sat, 28 Feb 2009 12:11:49 +0000</pubDate>
<dc:creator>greenshady</dc:creator>
<guid isPermaLink="false">1001000@http://wordpress.org/support/</guid>
<description>&#60;p&#62;Maybe something like this.&#60;/p&#62;
&#60;p&#62;Replace this:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;&#38;lt;?php $current_tag = single_tag_title(); ?&#38;gt;&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;With this:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;&#38;lt;?php
	global $wp_query;
	$tag = $wp_query-&#38;gt;get_queried_object();
	$current_tag = $tag-&#38;gt;term_id;
?&#38;gt;&#60;/code&#62;&#60;/pre&#62;</description>
</item>
<item>
<title>patcheta on "passing current single_tag_title as variable into new wp_query"</title>
<link>http://wordpress.org/support/topic/247918#post-999454</link>
<pubDate>Thu, 26 Feb 2009 22:03:04 +0000</pubDate>
<dc:creator>patcheta</dc:creator>
<guid isPermaLink="false">999454@http://wordpress.org/support/</guid>
<description>&#60;p&#62;Hi there, I'm trying to get the current tag of my post to then pass as a variable into a new wp_query so that I can show other posts that share the same tag. I'm also excluding the current post from the query so that it doesn't show up twice. I just read through all the pages in wp_query support forum and I'm still not getting it. I know it has to be a simple answer. A little new to php so I'm guessing it's my syntax. I'd really appreciate any help. Thanks.&#60;/p&#62;
&#60;p&#62;HERE IS MY CODE:&#60;/p&#62;
&#60;p&#62;&#38;lt;?php $current_tag = single_tag_title(); ?&#38;gt;&#60;br /&#62;
&#38;lt;?php&#60;br /&#62;
    $temp = $wp_query;&#60;br /&#62;
    $wp_query = null;&#60;br /&#62;
    $wp_query = new WP_Query();&#60;br /&#62;
    $wp_query-&#38;gt;query('tag='. $current_tag);&#60;br /&#62;
?&#38;gt;&#60;br /&#62;
&#38;lt;?php while ($wp_query-&#38;gt;have_posts()) : $wp_query-&#38;gt;the_post();&#60;br /&#62;
    if( $post-&#38;gt;ID == $do_not_duplicate ) continue;&#60;br /&#62;
    update_post_caches($posts); ?&#38;gt;
&#60;/p&#62;</description>
</item>

</channel>
</rss>
