• Hello,

    I want to set a certain category as main category.
    For that I made a custum Attribut #_ATT{Hauptkategorie}

    Then I hook into em_event_get_categories:

    add_filter('em_event_get_categories','my_em_event_get_categories',99,2);
    function my_em_event_get_categories($categories, $EM_Event){
    $Hauptkategorie = $EM_Event->event_attributes["Hauptkategorie"];
    foreach($categories as $Key => $EM_Category){
    if ( (strtoupper($EM_Category->name) === trim(strtoupper($Hauptkategorie)) )
    || (strtoupper($EM_Category->slug) === trim(strtoupper($Hauptkategorie)) ) ) {
            // this should set my Main Category as first
    	//$catTemp = $EM_Category;
    	//unset($EM_Category);
    	//array_unshift($categories, $catTemp); 
    
    }
    }
    return $categories
    }

    But this approach does not work because $categories ist an Object of Iterator.
    Is there anyone who has an idea how to put the correctly detected Main Category as first Element in the Categories List?

    thanks for help

    Frank

    https://wordpress.org/plugins/events-manager/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter frankhofmann

    (@frankhofmann)

    Plugin Support angelo_nwl

    (@angelo_nwl)

    hi,

    sorry for the confusion but can you give us more info please? also, are you trying to set custom event attributes as your Main Category?

    Thread Starter frankhofmann

    (@frankhofmann)

    Hello,

    Yes, I want to set the string in this attribute as the Main Categroy.

    Main Category is in my thinking the first categrory in the $categories collection.

    the $EM_Event Object gets his categroy by $EM_Categories->get_first()
    so I think this should be the way.

    function my_em_event_get_categories($categories, $EM_Event)

    Works perfect for me.
    I get the categories assigned to the event and allso the event attributes.
    The only thing is: I can not put the detected category as first element and return the collection in new order.

    best regards
    Frank

    Thread Starter frankhofmann

    (@frankhofmann)

    To be honest, it might be that my lack of knowledge how to work with Classses that instatiate Iterator is the problem.

    Thread Starter frankhofmann

    (@frankhofmann)

    I try to make it more clear.
    I want to make that categorie to my Main Category, where $EM_Category->name or $EM_Category->slug matches my custom event attribute.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Setting first Event category’ is closed to new replies.