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

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...

Pagoda panel installation failure prompt "ModulaNotFoundError: No module named 'gevent'" troubleshooting and solutions

Recently, a customer reported that when installing the pagoda panel, they received a message...

Linux adds Swap partition to solve memory shortage problem

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

Simple Method for Setting Linux VPS System Synchronization Time and Time Zone

80% of VPS users may choose their preferred system directly after purchasing VPS, and then...

How to modify server DNS address in Linux

DNS is a server used to resolve the backend IP of domain names. Linux, like Windows, has...