Need help listing organizer categories

Home Forums Calendar Products Events Calendar PRO Need help listing organizer categories

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #1229133
    Garrett
    Participant

    Hi!

    I love the plugin, and think it’s the best I’ve seen for calendars/events!

    That said, i wanted to reach out and see if you can help me with something: I’m trying to create a list view of all organizers in the system (like is provided by [list_organizers] snippet, but I also want to be able to list relative events categories for them.

    For example: If I have 3 organizers (Org1, Org2, Org3), and seven events categories (Cat1-7). Org1, has posted events with categories 1-3, while Org2 has posted events under categories 2-4, and Org3 has posted events under only one category (5). What I would want to create would look something like this:

    Org Name Category
    Org1 Cat1, Cat2, Cat3
    Org2 Cat2, Cat3, Cat4
    Org3 Cat5

    It would also be cool to be able to have the list link to org pages, or the category tags link to events of the same category.

    Do you have this functionality in shortcode somewhere, or can you point me in the right direction to be able to create a function to achieve this myself?

    Thanks for your time!
    ~G

    #1230155
    Nico
    Member

    Hi there Garret,

    Thanks for getting in touch with us! Interesting request here 🙂

    I can surely point you in the right direction! Not develop this for you but give you some tips.

    Please give me a bit of time to investigate the best possible way to do this and I’ll get back to you,
    Best,
    Nico

    #1231305
    Nico
    Member

    Hey Garret,

    I could give this some minutes, and I ended up developing much of the code. It’s wrapped up in a shortcode, so just paste the snippet below in your theme’s (or child theme’s) functions.php file and then place the shortcode in a page:

    // Sample code for custom organizer list
    // [tribe_custom_organizers]
    function do_tribe_custom_organizers( $atts ){

    $output = '';

    $organizers = tribe_get_organizers ( );

    foreach ( $organizers as $organizer ) {

    // Add Organizer
    // use tribe_get_organizer_link to get the link
    $output .= '- ' . $organizer->post_title . '</br>';

    // get organizer events (upcoming)
    $args = array(
    'organizer' => $organizer->ID,
    'eventDisplay' => 'list',
    'posts_per_page' => -1,
    );

    $events = Tribe__Events__Query::getEvents( $args, false );

    // get the cats
    $organizer_cats = array();
    foreach ( $events as $event ) {

    $event_cats = get_the_terms( $event->ID, Tribe__Events__Main::TAXONOMY );

    var_dump( $event_cats );

    foreach ( $event_cats as $cat ) {

    // avoid printig the term more than once
    if ( !in_array( $cat->term_id, $organizer_cats) ) {

    $organizer_cats[] = $cat->term_id;

    // use get_term_link to link the term
    $output .= '-- ' . $cat->name . '</br>';
    }
    }

    }
    }

    return $output;
    }
    add_shortcode( 'tribe_custom_organizers', 'do_tribe_custom_organizers' );

    There are a lot of loops in the code so probably won’t be super performant if there are many organizers with upcoming events with lot’s of category. I guess it can be optimized quite a bit but I’ll leave that for you 😉

    Hope it helps,
    Best,
    Nico

    #1234214
    Garrett
    Participant

    Thanks for the help! I think we’re 90% of the way there. It seems to be outputting the entire array as well as our intended results:

    CURRENT OUTPUT:

    array(1) { [0]=> object(WP_Term)#1787 (10) { [“term_id”]=> int(3) [“name”]=> string(14) “Climate Change” [“slug”]=> string(14) “climate-change” [“term_group”]=> int(0) [“term_taxonomy_id”]=> int(3) [“taxonomy”]=> string(16) “tribe_events_cat” [“description”]=> string(0) “” [“parent”]=> int(0) [“count”]=> int(4) [“filter”]=> string(3) “raw” } } array(3) { [0]=> object(WP_Term)#1789 (10) { [“term_id”]=> int(2) [“name”]=> string(12) “Civil Rights” [“slug”]=> string(12) “civil-rights” [“term_group”]=> int(0) [“term_taxonomy_id”]=> int(2) [“taxonomy”]=> string(16) “tribe_events_cat” [“description”]=> string(0) “” [“parent”]=> int(0) [“count”]=> int(4) [“filter”]=> string(3) “raw” } [1]=> object(WP_Term)#1790 (10) { [“term_id”]=> int(3) [“name”]=> string(14) “Climate Change” [“slug”]=> string(14) “climate-change” [“term_group”]=> int(0) [“term_taxonomy_id”]=> int(3) [“taxonomy”]=> string(16) “tribe_events_cat” [“description”]=> string(0) “” [“parent”]=> int(0) [“count”]=> int(4) [“filter”]=> string(3) “raw” } [2]=> object(WP_Term)#1786 (10) { [“term_id”]=> int(5) [“name”]=> string(14) “Women’s Rights” [“slug”]=> string(13) “womens-rights” [“term_group”]=> int(0) [“term_taxonomy_id”]=> int(5) [“taxonomy”]=> string(16) “tribe_events_cat” [“description”]=> string(0) “” [“parent”]=> int(0) [“count”]=> int(2) [“filter”]=> string(3) “raw” } } array(1) { [0]=> object(WP_Term)#1648 (10) { [“term_id”]=> int(3) [“name”]=> string(14) “Climate Change” [“slug”]=> string(14) “climate-change” [“term_group”]=> int(0) [“term_taxonomy_id”]=> int(3) [“taxonomy”]=> string(16) “tribe_events_cat” [“description”]=> string(0) “” [“parent”]=> int(0) [“count”]=> int(4) [“filter”]=> string(3) “raw” } } array(2) { [0]=> object(WP_Term)#1789 (10) { [“term_id”]=> int(2) [“name”]=> string(12) “Civil Rights” [“slug”]=> string(12) “civil-rights” [“term_group”]=> int(0) [“term_taxonomy_id”]=> int(2) [“taxonomy”]=> string(16) “tribe_events_cat” [“description”]=> string(0) “” [“parent”]=> int(0) [“count”]=> int(4) [“filter”]=> string(3) “raw” } [1]=> object(WP_Term)#1653 (10) { [“term_id”]=> int(3) [“name”]=> string(14) “Climate Change” [“slug”]=> string(14) “climate-change” [“term_group”]=> int(0) [“term_taxonomy_id”]=> int(3) [“taxonomy”]=> string(16) “tribe_events_cat” [“description”]=> string(0) “” [“parent”]=> int(0) [“count”]=> int(4) [“filter”]=> string(3) “raw” } } array(1) { [0]=> object(WP_Term)#1786 (10) { [“term_id”]=> int(5) [“name”]=> string(14) “Women’s Rights” [“slug”]=> string(13) “womens-rights” [“term_group”]=> int(0) [“term_taxonomy_id”]=> int(5) [“taxonomy”]=> string(16) “tribe_events_cat” [“description”]=> string(0) “” [“parent”]=> int(0) [“count”]=> int(2) [“filter”]=> string(3) “raw” } }
    – Hawaii Action Network
    — Climate Change
    — Civil Rights
    — Women’s Rights

    Also, is there a way to output in list form?

    Such as:

    • Hawaii Action Network
    • Climate Change
    • Civil Rights
    • Women’s Rights

    Thanks so much!

    #1234510
    Nico
    Member

    Sure, try this updated code:

    // Sample code for custom organizer list
    // [tribe_custom_organizers]
    function do_tribe_custom_organizers( $atts ){

    $output = '';

    $organizers = tribe_get_organizers ( );

    if ( !empty($organizers) ) $output .= '

      ';

      foreach ( $organizers as $organizer ) {

      // Add Organizer
      // use tribe_get_organizer_link to get the link
      $output .= '

    • ' . $organizer->post_title . '
    • ';

      // get organizer events (upcoming)
      $args = array(
      'organizer' => $organizer->ID,
      'eventDisplay' => 'list',
      'posts_per_page' => -1,
      );

      $events = Tribe__Events__Query::getEvents( $args, false );

      // get the cats
      $organizer_cats = array();

      foreach ( $events as $event ) {

      $event_cats = get_the_terms( $event->ID, Tribe__Events__Main::TAXONOMY );

      if( !empty($event_cats) ) $output .= '

      ';

      foreach ( $event_cats as $cat ) {

      // avoid printig the term more than once
      if ( !in_array( $cat->term_id, $organizer_cats) ) {

      $organizer_cats[] = $cat->term_id;

      // use get_term_link to link the term
      $output .= '

    • ' . $cat->name . '
    • ';
      }
      }

      if( !empty($event_cats) ) $output .= '

    ';

    }
    }

    if ( !empty($organizers) ) $output .= '';

    return $output;
    }
    add_shortcode( 'tribe_custom_organizers', 'do_tribe_custom_organizers' );

    Hope that works,
    Best,
    Nico

    #1242416
    Garrett
    Participant

    Thanks Nico!

    I checked out your code and it was creating a lot of

      in the html that were unnecessary, and seemed to be originating from the logic.

      I updated your code here, and commented out the original pieces so you can easily see the changes. What i’m left with is a very clean output:

      <ul class="orglist">
        <li class="orglist-org">Org 1 Name</li>
          <ul>
            <li class="orglist-category">Cat1</li>
          </ul>
        <li class="orglist-org">Org 2 name</li>
          <ul>
            <li class="orglist-category">Cat1</li>
            <li class="orglist-category">Cat2</li>
            <li class="orglist-category">Cat3</li>\
          </ul>
      </ul>

      Here’s the updated code, and thanks again!:

      //CUSTOM ORGANIZER LIST //
      // Sample code for custom organizer list
      // [tribe_custom_organizers]
      function do_tribe_custom_organizers( $atts ){
           
          $output = '';
       
          $organizers = tribe_get_organizers ( );
       
          if ( !empty($organizers) ) $output .= '<ul class="orglist">';
       
          foreach ( $organizers as $organizer ) {
               
              // Add Organizer
              // use tribe_get_organizer_link to get the link
              $output .= '<li class="orglist-org">' . $organizer->post_title . '</li>';
       
              // get organizer events (upcoming)
              $args = array( 
                          'organizer'      => $organizer->ID,
                          'eventDisplay'   => 'list',
                          'posts_per_page' => -1,
                      );
       
              $events = Tribe__Events__Query::getEvents( $args, false );
       
              // get the cats
              $organizer_cats = array();
      		$output .= '<ul>';
              foreach ( $events as $event ) {
                   
                  $event_cats = get_the_terms( $event->ID, Tribe__Events__Main::TAXONOMY );
                   
                  //if( !empty($event_cats) ) $output .= '<ul>';
       
                  foreach ( $event_cats as $cat ) {
      				
                      // avoid printig the term more than once
                      if ( !in_array( $cat->term_id, $organizer_cats) ) {
       
                          $organizer_cats[] = $cat->term_id;
       
                          // use get_term_link to link the term
                          $output .= '<li class="orglist-category">' . $cat->name . '</li>';
                      }
                  }
       
                  //if( !empty($event_cats) ) $output .= '</ul>';
                   
              }
      		$output .='</ul>';
          }
       
          if ( !empty($organizers) ) $output .= '</ul>';
       
          return $output;
      }
      add_shortcode( 'tribe_custom_organizers', 'do_tribe_custom_organizers' );
      #1242623
      Nico
      Member

      Thanks for following up with the updated code Garret! Seems like I was duplicating the ul tag.

      Anyway I’m glad you could adapt the script 🙂

      I’ll go ahead and close out this thread, but if you need help with anything else please don’t hesitate to create a new one and we will be happy to assist you.

      Best,
      Nico

    Viewing 7 posts - 1 through 7 (of 7 total)
    • The topic ‘Need help listing organizer categories’ is closed to new replies.