Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting a taxonomy term for the current post in wordpress

Tags:

wordpress

I'm trying to populate a form value field with a taxonomy term associated with the current post,

I must have tried 20 things but cant find the right solution .?

I have meta fields but that's easy I have just used this:

$ref = get_post_meta( $post->ID, 'job_ref', true ); 

and this for the form field:

  <input type="text" class="text" name="job_ref" id="job_ref" value="
  <?php echo $ref; ?>" /> 

So I'm looking for a similar solution for a taxonomy term ..?

Many thanks

like image 640
Ledgemonkey Avatar asked Dec 11 '22 20:12

Ledgemonkey


2 Answers

Use wp_get_post_terms to retrieve your post terms. syntax here:

http://codex.wordpress.org/Function_Reference/wp_get_post_terms

like image 95
barakadam Avatar answered Mar 25 '23 09:03

barakadam


You can use get_the_terms(). The difference between get_the_terms() and wp_get_post_terms() is that get_the_terms()'s results are cached.

like image 40
j08691 Avatar answered Mar 25 '23 08:03

j08691