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

Method for modifying server hostname in Linux system

How to modify the hostname in LinuxHow to modify the Linux hostname? You can temporarily modify...

Can websites not use SSL certificates? There may be issues with websites not installing SSL certificates

Website security certificate, also known as website SSL certificate. Nowadays, we see many...

Linux adds Swap partition to solve memory shortage problem

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

CERTUM Certificate Brand Information

CERTUM was founded in Poland in 1998 and has developed into a professional certification body in...

Several commands for viewing hard disk information in Linux

Viewing server hard disk information is one of the daily tasks of system administrators. This...