On previous days I’m working on GetaJob Website, GetaJob is a site dedicated to all Filipinos looking for jobs online, and employers looking to hire Filipinos. My task on the site is to get all Job Category (a custom taxonomy) and display Job Category (a custom taxonomy) on each Job listed or Post, lets begin with this short wordpress tutorials.
PHP
1
2
3
4
5
6
7
8
<?php
$terms = get_the_terms( $post->ID , ‘taxonomy-name’ );
if($terms) {
   foreach( $terms as $term ) {
      echo $term->term_id.’<br />’;
   }
}
?>

What is get_the_terms() WordPress function?

get_the terms() Retrieve the terms of the taxonomy that are attached to the post, visitWordPress codex for more information.
To get the taxonomy name on each particular custom taxonomy ID, change the above code to this
PHP
1
2
3
4
5
6
7
8
9
10
<?php
$terms = get_the_terms( $post->ID , ‘taxonomy-name’);
if($terms) {
   foreach( $terms as $term ) {
      $ts = get_term($term->term_id, ‘taxonomy-name’);
      $n = $ts->name;
      echo $n;
   }
}
?>
That’s it a very simple tutorial, hope this will help in your WordPress project and web development.

0 comments:

Post a Comment

 
Top