Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

How do you extract the url from :

$url = get_the_term_list($post->ID, 'nom-origin')

I have tried many things but i just don't get it. The only solution i got was this but i know it's just too messy :

$url = get_the_term_list($post->ID, 'nom-origin');//,'<h3>Job Category:</h3> ', ', ', '' );
$url_tmp1 = explode("href=\"",$url);
$url_tmp2 = explode("\" rel=\"tag\">",$url_tmp1[1]);
$url_simple = $url_tmp2[0];
share|improve this question

2 Answers 2

get_term_link gives you the link of a particular taxonomy term.

$terms = get_object_terms( $post->ID, 'nom-origin' );
$urls = array();
foreach( $terms as $term )
{
    $url[] = get_term_link( $term->slug, 'nom-origin' );
    //Or do whatever you want here with the url
}
share|improve this answer
    
I will try that, thanks –  greta22 Mar 29 '13 at 15:16

Never try to parse complete markup when you don't have to. Follow the function calls.

  1. get_the_term_list uses get_the_terms
  2. get_the_terms returns an array of terms
  3. You can use that array plus get_term_link to get your URLs

And the code for that is in the Codex.

$terms = get_terms('species');
echo '<ul>';
  foreach ($terms as $term) {
    echo '<li><a href="'.get_term_link($term->slug,species').'">'.$term->name.'</a></li>';
  }
echo '</ul>';

You may want to build an array instead, but its the same idea:

$terms = get_terms('species');
$turls = array();
foreach ($terms as $term) {
    $turl[] = get_term_link($term->slug,'species');
}
share|improve this answer
    
Thanks s_ha_dum. This is definitely going in the good direction for me. And what if i want to link this to a thumbnail instaed of an name ? I have try $term->thumbnail but it doesn't work. –  greta22 Mar 29 '13 at 15:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.