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');

  • WordPress, 调用WordPress, WordPress自定义文章分类
  • 1 Users Found This Useful
Was this answer helpful?

Related Articles

How to change the root user password of Linux operating system

Changing the root user password of the Linux operating system is a critical operation, please...

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

Several of the most common encryption and decryption methods

Encryption and decryption are the most commonly used data conversion methods in communication....

Method for modifying server hostname in Linux system

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

Linux adds Swap partition to solve memory shortage problem

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