2017-04-19 51 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') 

让我知道如果你需要进一步的帮助......