Call WordPress to customize the content of article categories

If we have a custom WordPress article classification, how can we operate it separately if needed.
function wp_list_categories_for_post_type($post_type, $args = '') {
$exclude = array();
//Retrieve the classification of articles of the specified article type (or custom article type)
foreach (get_categories() as $category) {
$posts = get_posts(array('post_type' => $post_type, 'category' => $category->cat_ID));
//If not found
if (empty($posts))
//Add category ID to exclusion list
$exclude[] = $category->cat_ID;
}
//Set query parameter arg
if (! empty($exclude)) {
$args .= ('' === $args) ? '' : '&';
$args .= ' exclude='.implode(',', $exclude);
}
//Display category
wp_list_categories($args);
}
Select CodeCopy
Add to functions.php.
For example, if there is a custom article type called movie, obtain the classification of the movie.
wp_list_categories_for_post_type('movie');
Select CodeCopy
Then call it like this:
p_list_categories_for_post_type('movie','order=DESC&title_li=Cats');

  • 1 Users Found This Useful
Was this answer helpful?

Related Articles

Common commands for Linux server systems

Linux is widely used in the field of server operating systems, and the vast majority of Linux...

The meaning and characteristics of the. io suffix domain name, as well as its suitability for the domain (whether it is worth registering)

IO is the abbreviation for British Indian Ocean Territory, therefore the. io domain is also...

Linux adds Swap partition to solve memory shortage problem

preparationFirstly, check if your system already has a Swap partition:swapon -sorfree -mIf no...

Requirements and usage suggestions for. app domain registration

.app域名是由Google推出的顶级域名(TLD),旨在提供安全的在线体验。作为.app域名的管理机构,Google要求所有.app域名都必须使用HTTPS来加密数据传输,以确保用户隐私和安全...

What is a. ai domain name? Is an AI domain worth registering? Can DNSHE register an AI domain name?

The. ai domain represents one of the most important innovations of humanity, artificial...