因此,我正在处理该sinlge-download.php
页面,并尝试检查特定产品是否属于特定类别。这是我尝试过的,但即使下载的是一本书,我也只能得到 ELSE 结果。
if( in_category( 'Books' ) ) {
echo 'This product is a book';
} else {
echo 'This product is not a book';
}
因此,我正在处理该sinlge-download.php
页面,并尝试检查特定产品是否属于特定类别。这是我尝试过的,但即使下载的是一本书,我也只能得到 ELSE 结果。
if( in_category( 'Books' ) ) {
echo 'This product is a book';
} else {
echo 'This product is not a book';
}
根据 EDD 文档,该类别是:download_category
Easy Digital Download Docs
为此...使用函数has_term
,因为它in_category
指的是 WordPresspost
类型posts
,而不是像下载这样的自定义帖子类型。
if( has_term( 'Books', 'download_category' ) ) {
echo 'This product is a book';
} else {
echo 'This product is not a book';
}
你可以用这个
if( has_term( $term = '', $taxonomy = '', $post = null ) ) {
// do something
}
// $term = Category OR Taxonomy name $taxonomy = Taxonomy Name. OR
// "category" if its default WP category $post = Post ID to check. Leave
// empty to pull this from global query
https://developer.wordpress.org/reference/functions/has_term/