1

因此,我正在处理该sinlge-download.php页面,并尝试检查特定产品是否属于特定类别。这是我尝试过的,但即使下载的是一本书,我也只能得到 ELSE 结果。

if( in_category( 'Books' ) ) {
    echo 'This product is a book';
   } else {
    echo 'This product is not a book';
   }
4

2 回答 2

1

根据 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';
}
于 2020-02-24T10:34:13.043 回答
0

你可以用这个

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/

于 2020-02-24T06:28:12.357 回答