Link to home
Start Free TrialLog in
Avatar of Jon Imms
Jon ImmsFlag for United States of America

asked on

Get Taxonomy Description

Hi there,
I have a custom XML feed, which displays all 2500 of our job posts.
for that, i have  a wordpress taxonomy created with PODS called Fleets (taxonomy=fleets)
I have 72 fleets, and all have descriptions.
How do I display the description of the current fleet?

I've tried :

Displays  -  Truck Driving Job
		
<title><![CDATA[<?php echo term_description( $post->ID, 'fleets'); ?> -  Truck Driving Job ]]></title>

Open in new window

Error:
		<title><![CDATA[<?php echo term_description( 'fleets'); ?> Truck Driving Job ]]></title>

Open in new window


Anybody know how to display correctly?

<?php
/**
* Template Name: Custom RSS Template - spthuntfeed
*/
$postCount = 500; // The number of posts to show in the feed
$cacheFile = "wp-content/themes/enfold/rsscache/spthuntfeed.rss";

if(!file_exists(dirname($cacheFile)))
{
  mkdir(dirname($cacheFile));
}

$posts_per_page = 50;
$paged = 0;
$theres_more = true;
$rss_items = array();
if(file_exists($cacheFile) && !isset($_GET["reset"]))
{
  $rss_items = json_decode(file_get_contents($cacheFile),true);
  if($rss_items == null) { $rss_items = array(); }
}

$charset = get_option( 'blog_charset' );
header( 'Content-Type: ' . feed_content_type( 'rss-http' ) . '; charset=' . $charset, true );
?>
<?php echo '<'.'?xml version="1.0" encoding="utf-8"?'.'>'; ?>
<source>
<title><?php bloginfo_rss( 'name' ); ?> - SmartPhoneTrucker - Hunt Transportation Job Feed</title>
<link><?php bloginfo_rss('url'); ?></link>
<description><?php bloginfo_rss('description'); ?></description>
<lastBuildDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_lastpostmodified('GMT'), false); ?></lastBuildDate>
<language>en</language>

<?php
while($theres_more)
{
  $result = query_posts( array(
    'post_type' => 'job_listing',
    'paged' => $paged,
    'posts_per_page' => $posts_per_page,
    'tax_query' => array(
        array(
            'taxonomy' => 'job_listing_type', //or tag or custom taxonomy
            'field' => 'id',
            'terms' => array('499')
        )
    )
  ) );

  $number_of_results = count($result);


  while(have_posts())
  {
    // Get the next post
    the_post();

    // Check the cache
    if(isset($rss_items[$post->ID]) && (strtotime($rss_items[$post->ID][0]) == strtotime($post->post_modified)))
    {
      // We have a cached item with the same modified date
      echo $rss_items[$post->ID][1];
    }
    else
    {
      // Either the item isn't cached or the last-modified date has changed
      ob_start();
    ?>
	 <job>
	 	<referencenumber><![CDATA[<?php the_ID(); ?>]]></referencenumber>
		
		<title><![CDATA[<?php echo term_description( $post->ID, 'fleets'); ?> Truck Driving Job ]]></title>

		<date><![CDATA[<?php echo mysql2date('D, d M Y H:i:s +0000', get_post_time('Y-m-d H:i:s', true), false); ?>]]></date>
		<url><![CDATA[<?php the_permalink_rss(); ?>?utm_source=HuntSmartPhoneTruckerXMLFeed]]></url>
		<city>
                <?php 
					// Use an output buffer to put the output of the_job_location() into a variable with the same name
					ob_start(); the_job_location(); $the_job_location = ob_get_clean(); 

					// Now extract the content between the ">" and the "<"
					$pos1 = strrpos($the_job_location, "<"); // Find the "<" of the "</a>" tag
					$pos2 = strrpos($the_job_location, ">", $pos1-strlen($the_job_location)) + 1; // Find the last ">" that occurs before the "</a>" tag
					$the_job_location = substr($the_job_location, $pos2, ($pos1-$pos2));

					// And display the text e.g. "Wheatland, WY, United States"
					//echo $the_job_location;
					echo preg_replace('/([^,]+).*/', '$1', $the_job_location );

				?>
		</city>
		
		<?php
			$mystr=get_the_term_list( $post->ID, 'states');
			$temp=strpos($mystr,">");
			$states=str_replace("</a>","",substr($mystr,$temp+1));
		?>
		<state><![CDATA[<?php echo $states; ?>]]></state>
		<country><![CDATA[US]]></country>	
		<?php
			$mystr=get_the_term_list( $post->ID, 'job_listing_category');
			$myseperator=',';
			$mycount=0;
			$drivertype='';
				while(strstr($mystr,">")){
					$temp_a=strpos($mystr,">")+1;
					$temp_b=strpos($mystr,"<",$temp_a);
					$value_length=$temp_b-$temp_a;
					$value=substr($mystr,$temp_a,$value_length);
					$mystr=substr($mystr,($temp_b+4));//add the number of characters in "</a>" which is 4
				if($mycount>0){$drivertype.=$myseperator;}
					$drivertype.=$value;
					$mycount++;
			}
		?>
		<jobtype><![CDATA[<?php echo $drivertype; ?>]]></jobtype>
		<freight><![CDATA[FlatBed]]></freight>
		<description><![CDATA[<?php the_excerpt(); echo do_shortcode( '[about-hunt]' ); ?>]]></description>
		<requirements><![CDATA[<?php echo do_shortcode( '[Qualifications]' ); ?>]]></requirements>

		
	</job>

				
      <?php

      // Get the item's RSS content and add it to the array
      $rss_item = ob_get_flush();
      $rss_items[$post->ID] = array($post->post_modified, $rss_item);
    }
  }

  // Save our updates after every page
  file_put_contents($cacheFile, json_encode($rss_items));

  // Check to see if there are more pages
  $theres_more = ($number_of_results == $posts_per_page);
  $paged++;
}
  ?>
  </source>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Jon Imms
Jon Imms
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial