• Resolved stuffen17

    (@stuffen17)


    Hello,

    I am really not getting this together. I just want to add a custom column to my “events” admin page. I already added the column, however, I cannot seem to get the right command to get the category.

    Can someone help me out?

    function event_manager_categories_content($column, $post_id) {
    	 global $event;
    		switch ($column) {
    			case 'category':
    			$emcategory = get_term_by('id', $post_id, 'event-categories');
    			$emcategoryname = $term->name;
    			echo $emcategoryname;

    I really have a problem with all the names in EM. Where do I get all the right names? E.g. for taxonomy I already read “event-categories” but also “EM_TAXONOMIES_CATEGORY”. Which is the right one and how can I find out myself?

    – Thanks already.

    https://www.ads-software.com/plugins/events-manager/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi,

    There are a couple of things that might be wrong. The first is that lines 5 and 6 don’t match.

    If you’re calling get_term_by as $emcategory, then the next line should be:

    $emcategoryname = $emcategory->name;

    Thread Starter stuffen17

    (@stuffen17)

    Hello,

    thanks for the help.

    For sure I did some mistakes there, however, it was not the only code I tried. (I looked up get_term_by and I suppose it′s only working for a CATEGORY ID, not post_id.)

    In another support post someone writes that with this code I get the categories:
    $cat = $EM_Event->get_categories()->categories;

    Now I suppose I have an Object which is an array of category objects?!

    How do I access the category name from there?

    already tried
    $cat->name
    with no luck.

    Alternatively
    get_the_terms( $post_id, 'event-categories' ) this should get me also the categories, same as the upper code – right?
    Here the same problem – how do I get the category name from here on?

    Plugin Support angelo_nwl

    (@angelo_nwl)

    Thread Starter stuffen17

    (@stuffen17)

    Hello angelo,

    I already got the column to show, as shown in the tutorial above. However, as I said before, I have trouble getting the actual Category Name by post_id (because I do not quite understand the structure of the objects). I can′t seem to get the code right… I was hoping some1 could help me with those 2-3 lines of code.

    I think the first step, based on the example code you gave earlier, is to try

    print($cat);

    That should print the array structure to the screen. If it doesn’t, you know the preceding code isn’t correct.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Customn Column – Get Category’ is closed to new replies.