Get event categories in Wordpress Calendar Calendar Pro Plugin

I use the Events Calendar Pro plugin ( https://theeventscalendar.com/product/wordpress-events-calendar-pro/ ) and I need to get all categories for each event.

I tried single_cat_title()and get_the_category(), but I do not need them.

In fact, the function single_cat_title()shows only the first category, but get_the_category()returns an empty array.

+4
source share
2 answers

You can use the following code to get detailed information about each term.

$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.

, .

+2

single_cat_title() get_the_category(), .

get_the_category() , . , Calendar pro, , get_the_terms().

get_the_terms() post_id /.

, , : -

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

, ...

+2

Source: https://habr.com/ru/post/1675110/


All Articles