# get\_terms, get\_term (ok)

## get\_terms

_**Ví dụ 1:**_

```
<?php
// mảng taxonomies
$taxonomies = array(
  'post_tag'
);
$args = array(
  'orderby'                => 'name'
);
$terms = get_terms($taxonomies, $args);
echo '<pre>';
	var_export($terms);
echo '</pre>';
?>
```

![](https://2370029328-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LWPtKFbhw0XehxVuoiZ%2F-M9XFbn7PohhiJPqErU3%2F-M9XHu6eBcWRQ60Ce8H4%2FScreenshot_11.png?alt=media\&token=cdd5bb6b-0e30-4077-bcb2-dfa3f2e8c1e2)

![](https://2370029328-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LWPtKFbhw0XehxVuoiZ%2F-M9XFbn7PohhiJPqErU3%2F-M9XHxIYjZtdQ0ujaLbd%2FScreenshot_12.png?alt=media\&token=02ef67b2-75c0-4995-8383-5de787a916ea)

Kết quả:

![](https://2370029328-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LWPtKFbhw0XehxVuoiZ%2F-M9XI-RPl90uA_mii0G0%2F-M9XI5wMtibwb9r_xE7y%2FScreenshot_13.png?alt=media\&token=2b5019f3-294e-45f0-b7be-dfed2624cfc3)

_**Ví dụ 2:**_&#x20;

C:\xampp\htdocs\wordpress\wp-content\themes\twentytwentyone\functions.php

```
add_action('init', 'my_book_cpt');
function my_book_cpt() {
  $labels = array(
    'name'               => _x('Books', 'post type general name', 'your-plugin-textdomain'),
    'singular_name'      => _x('Book', 'post type singular name', 'your-plugin-textdomain'),
    'menu_name'          => _x('Books', 'admin menu', 'your-plugin-textdomain'),
    'name_admin_bar'     => _x('Book', 'add new on admin bar', 'your-plugin-textdomain'),
    'add_new'            => _x('Add New', 'book', 'your-plugin-textdomain'),
    'add_new_item'       => __('Add New Book', 'your-plugin-textdomain'),
    'new_item'           => __('New Book', 'your-plugin-textdomain'),
    'edit_item'          => __('Edit Book', 'your-plugin-textdomain'),
    'view_item'          => __('View Book', 'your-plugin-textdomain'),
    'all_items'          => __('All Books', 'your-plugin-textdomain'),
    'search_items'       => __('Search Books', 'your-plugin-textdomain'),
    'parent_item_colon'  => __('Parent Books:', 'your-plugin-textdomain'),
    'not_found'          => __('No books found.', 'your-plugin-textdomain'),
    'not_found_in_trash' => __('No books found in Trash.', 'your-plugin-textdomain'),
  );
  $args = array(
    'labels'             => $labels,
    'description'        => __('Description.', 'your-plugin-textdomain'),
    'public'             => true,
    'publicly_queryable' => true,
    'show_ui'            => true,
    'show_in_menu'       => true,
    'query_var'          => true,
    'rewrite'            => array('slug' => 'book'),
    'capability_type'    => 'post',
    'has_archive'        => true,
    'hierarchical'       => false,
    'menu_position'      => null,
    'show_in_rest'       => true,
    'rest_base'          => 'books',
    'supports'           => array('title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments'),
  );
  register_post_type('book', $args);
  flush_rewrite_rules(true);
}
// ===========
add_action('init', 'my_book_taxonomy', 30);
function my_book_taxonomy() {
  $labels = array(
    'name'              => _x('Genres', 'taxonomy general name'),
    'singular_name'     => _x('Genre', 'taxonomy singular name'),
    'search_items'      => __('Search Genres'),
    'all_items'         => __('All Genres'),
    'parent_item'       => __('Parent Genre'),
    'parent_item_colon' => __('Parent Genre:'),
    'edit_item'         => __('Edit Genre'),
    'update_item'       => __('Update Genre'),
    'add_new_item'      => __('Add New Genre'),
    'new_item_name'     => __('New Genre Name'),
    'menu_name'         => __('Genre'),
  );
  $args = array(
    'hierarchical'      => true,
    'labels'            => $labels,
    'show_ui'           => true,
    'show_admin_column' => true,
    'query_var'         => true,
    'rewrite'           => array('slug' => 'genre'),
    'show_in_rest'      => true,
    'rest_base'         => 'genre',
  );
  register_taxonomy('genre', array('book'), $args);
  flush_rewrite_rules(true);
}
```

C:\xampp\htdocs\wordpress\wp-content\themes\twentytwentyone\single.php

```
// mảng taxonomies
$taxonomies = array(
  'post_tag',
  'category',
  'genre'
);
$args = array(
  'orderby'                => 'name'
);
$terms = get_terms($taxonomies, $args);
echo '<pre>';
	var_export($terms);
echo '</pre>';
```

_**Kết quả:**_

![](https://2370029328-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LWPtKFbhw0XehxVuoiZ%2F-MOin8f88iFSBznGozZw%2F-MOiokFZe-DIhdZj2R3f%2FScreenshot_1.png?alt=media\&token=31455d9a-6f9f-4a39-b091-65fe0a87aabc)

## get\_term

![](https://2370029328-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LWPtKFbhw0XehxVuoiZ%2F-M9XJLvtzOBXIRDEojsc%2F-M9XJYADOxSt4UdFGbX-%2FScreenshot_14.png?alt=media\&token=8bbef204-db21-4950-a434-f0863fe565b7)

![](https://2370029328-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LWPtKFbhw0XehxVuoiZ%2F-M9XJLvtzOBXIRDEojsc%2F-M9XJakH4n9GCzdto4f6%2FScreenshot_15.png?alt=media\&token=1e32b8de-fce5-4297-9c9a-010beb4dc99e)

![](https://2370029328-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LWPtKFbhw0XehxVuoiZ%2F-M9XJLvtzOBXIRDEojsc%2F-M9XJdNBtHlxDEhMkUsF%2FScreenshot_16.png?alt=media\&token=f69300b3-df32-4284-af43-8bc23ea7a943)

```
<?php
$term = get_term(1,'category');
echo '<pre>';
	var_export($term);
echo '</pre>';
?>
```

Vi du

![](https://2370029328-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LWPtKFbhw0XehxVuoiZ%2F-MA085KSYgkydeoTHFxM%2F-MA0CiPBFDJJDWaaf1-s%2FScreenshot_12.png?alt=media\&token=48c05641-a0a7-4067-93b6-6f79da097f3d)

![](https://2370029328-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LWPtKFbhw0XehxVuoiZ%2F-MA085KSYgkydeoTHFxM%2F-MA0Cl00XTOVOUWMk_le%2FScreenshot_13.png?alt=media\&token=05dd8ba0-0a3e-47e8-abfa-94e1dddeadd7)

Hoặc đơn giản hơn&#x20;

```
Sử dụng 
$taxonomies = 
array(
	  'pointfinderltypes'
	);
	$args = array(
	  'orderby'                => 'name'
	);
	$terms = get_terms($taxonomies, $args);
	echo '<pre>';
		var_export($terms);
	echo '</pre>';
Hoặc sử dụng code bên dưới đơn giản hơn.
$singer = get_the_terms( get_the_ID(), "pointfinderltypes" );
	echo '<pre>';
		var_export($singer);
	echo '</pre>';
```
