Support

Home Forums Event Espresso Premium Adding a custom taxonomy to Event Espresso Event

Adding a custom taxonomy to Event Espresso Event

Posted: January 9, 2017 at 8:30 am

Viewing 5 reply threads


Lume1916-18

January 9, 2017 at 8:30 am

I have tried this two ways, applying a filter to FHEE__EE_Register_CPTs__get_taxonomies__taxonomies and creating a taxonomy using the standard WP register_taxonomy and applying it using FHEE__EE_Register_CPTs__get_CPTs__cpts however I am not having any luck.

I am working off (https://eventespresso.com/topic/can-i-add-the-wp-core-categories-taxonomy-to-events/)


function atg_register_tax() {
  // Custom Taxonomy Code
  $args = array(
    "labels" => array(
	    "name"              => __( 'Sessions', 'atg' ),
	    "singular_name"     => __( 'Session', 'atg' ),
      'search_items'      => __( 'Sessions', 'atg' ),
      'all_items'         => __( 'All Sessions', 'atg' ),
      'parent_item'       => __( 'Parent Session', 'atg' ),
      'parent_item_colon' => __( 'Parent Session:', 'atg' ),
      'edit_item'         => __( 'Edit Session', 'atg' ),
      'update_item'       => __( 'Update Session', 'atg' ),
      'add_new_item'      => __( 'Add New Session', 'atg' ),
      'new_item_name'     => __( 'New Session Name', 'atg' ),
      'menu_name'         => __( 'Sessions', 'atg' ),
	  ),
    "hierarchical" => true,
    "show_ui" => true,
    "query_var" => true,
    "rewrite" => array( 'slug' => 'sessions' ),
    "show_admin_column" => true,
  );
  register_taxonomy( "sessions", array(), $args );
  // End Sessions  

  // ... Add More Taxonomies  
}
add_action( 'init', 'atg_register_tax' );

/**
 * Add Custom Taxonomy to Event Espresso
*/
function ee_add_category_to_event_cpt( $cpt_registry_array ) {
  if ( isset( $cpt_registry_array['espresso_events'] ) ) {
    $cpt_registry_array['espresso_events']['args']['taxonomies'] = array(
      'espresso_event_categories',
      'espresso_event_type',
      'sessions'
    );
  }
  return $cpt_registry_array;
}
add_filter( 'FHEE__EE_Register_CPTs__get_CPTs__cpts', 'ee_add_category_to_event_cpt' );


Josh

  • Support Staff

January 9, 2017 at 1:32 pm

Hi there,

When you add a taxonomy to a custom post type, you need to set the second parameter to the custom post type.

e.g.

register_taxonomy( 'sessions', 'espresso_events', $args );

See also:

https://konstantin.blog/2012/how-to-add-taxonomies-to-your-custom-post-types-in-wordpress/

https://codex.wordpress.org/Function_Reference/register_taxonomy


Lume1916-18

January 9, 2017 at 2:00 pm

Ah duh! my mistake, how about adding a menu item under management?


Lume1916-18

January 9, 2017 at 3:38 pm

I have worked this out like this, open to advise if you have a better way.


function atg_filter_menu_pages(){
  add_submenu_page('espresso_events', __('Sessions', 'event_espresso'), __('Sessions', 'event_espresso'), 'manage_options', 'edit-tags.php?taxonomy=sessions' );
}
add_action('admin_menu', 'atg_filter_menu_pages', 20);

function atg_select_parent_menu($file) {
  global $pagenow;
  if($pagenow = 'sessions')
    return 'espresso_events';
  else
    return $file;
}
add_filter('parent_file', 'atg_select_parent_menu');


Lume1916-18

January 10, 2017 at 7:58 am

Correction this is how i got the menu to highlight…


function atg_select_parent_menu($file) {
  global $pagenow;
  $menu_slug = $pagenow.'?'.$_SERVER['QUERY_STRING'];
  if($menu_slug == 'edit-tags.php?taxonomy=sessions' || $menu_slug == 'edit-tags.php?taxonomy=age' || $menu_slug == 'edit-tags.php?taxonomy=days')
    return 'espresso_events';
  else
    return $file;
}
add_filter('parent_file', 'atg_select_parent_menu');


Josh

  • Support Staff

January 11, 2017 at 8:59 am

I’m not clear on what exactly you’re trying to do with the above code, but if it’s working for you then that should be fine.

Viewing 5 reply threads

The support post ‘Adding a custom taxonomy to Event Espresso Event’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso