2. [POST & CATEGORY] wp_get_post_categories() (nó lấy id category)(ok)

https://developer.wordpress.org/reference/functions/wp_get_post_categories/

wp_get_post_categories( int $post_id, array $args = array() )

$post_id
(int) (Optional) The Post ID. Does not default to the ID of the global $post. Default 0.

$args
(array) (Optional) Category query parameters. See WP_Term_Query::__construct() for supported arguments.

Default value: array()

Ví dụ 1: Đây là mặc định

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

<?php  
	$categories = wp_get_post_categories(14,array('order' => 'ASC'));
	echo '<pre>';
		var_export($categories);
	echo '</pre>';
?>

Ví dụ 2: Đây là có sử dụng tham số tham khảo thêm tham số trang chủ :)

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

<?php  
		$categories = wp_get_post_categories(14,array('order' => 'DESC'));
		echo '<pre>';
			var_export($categories);
		echo '</pre>';
	?>

:: Chú ý: Tôi không thấy 'taxonomy' hoạt động :(

Last updated