2017-04-19 73 views
4

我使用Events Calendar Pro插件(https://theeventscalendar.com/product/wordpress-events-calendar-pro/),我需要獲取每個事件的所有類別。獲取Wordpress活動日曆Pro插件中的事件類別

我試過single_cat_title()get_the_category()但他們不是我所需要的。

實際上,single_cat_title()函數只顯示第一類,而get_the_category()返回空數組。

+0

我也面臨這個問題。讓我知道你得到了什麼。 – MrIndomitable

回答

2

您可以使用下面的代碼來獲得各方面的細節。

$cats = get_the_terms($post_id, 'tribe_events_cat'); 
$term = get_term($cats[1], $taxonomy); // Getting the 2nd term item 
$name = $term->name; //Getting names of terms 

https://codex.wordpress.org/Function_Reference/get_term的更多詳細信息。

讓我知道你是否還有其他問題。

+0

嘗試此操作,我爲$ cat獲得「bool(false)」 – Ralf

2

我試過single_cat_title()和get_the_category(),但它們不是我所需要的。

get_the_category()函數檢索默認類別,發佈類別。由於Events Calendar Pro插件定義的類別不是默認的,因此您需要使用get_the_terms()函數。

在get_the_terms()函數中,您需要傳遞post_id作爲第一個參數和分類/分類名稱。

因此,所有包裹起來,你可以試試下面的代碼: -

$event_cats = get_the_terms($post_id, 'tribe_events_cat') 

讓我知道如果你需要進一步的幫助......