php WordPress获取类别ID

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php WordPress获取类别ID相关的知识,希望对你有一定的参考价值。

<?php

// Get the "featured" category object.
$featured_category = get_term_by( 'slug', 'featured', 'category' );

// Set the "featured" category ID.
$featured_category_ID = $featured_category->term_id;

// Get the latest three posts, ignoring the current post
// and any in the "featured" category.
$args = array(
	'post_type'              => 'post',
	'posts_per_page'         => 3,
	'post__not_in'           => array( get_the_ID() ),
	'category__not_in'       => array( absint( $featured_category_ID ) ),
	'no_found_rows'          => true,
	'update_post_meta_cache' => false,
	'update_post_term_cache' => false,
);

// Run query.
$data = new WP_Query( $args );

以上是关于php WordPress获取类别ID的主要内容,如果未能解决你的问题,请参考以下文章

PHP Wordpress - 获取当前类别名称和/或ID

php WordPress |获取第一个类别名称,slug和ID

php WordPress |获取第一个类别名称,slug和ID

用于 WordPress 的 PHP 片段,用于获取所有产品子类别

Wordpress-获取当前类别名称和/或ID

如何在数组中列出 wordpress 类别 ID 和名称?