1

So I'm working with the sinlge-download.php page and I'm trying to check if the specific product is in a specific category. Here is what I tried but I only get the ELSE result even if the download is a book.

if( in_category( 'Books' ) ) {
    echo 'This product is a book';
   } else {
    echo 'This product is not a book';
   }
idomskt
  • 47
  • 1
  • 6
  • What kind of taxonomy is "Books"? – Howard E Feb 23 '20 at 23:55
  • Books is the category of the Easy Digital Downloads product. EDD products are custom post type called ‘download’. I would like to check if the download page is in the Books category – idomskt Feb 24 '20 at 01:03

2 Answers2

1

According to EDD docs, the category is: download_category Easy Digital Download Docs

For this... use function has_term since in_category refers to WordPress post type posts and not for custom post types like the downloads.

if( has_term( 'Books', 'download_category' ) ) {
    echo 'This product is a book';
} else {
    echo 'This product is not a book';
}
Howard E
  • 5,454
  • 3
  • 15
  • 24
0

You can use this

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/

Kay
  • 498
  • 3
  • 14