Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Nov 10th, 2011  |  syntax: None  |  size: 1.22 KB  |  hits: 96  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. add_action('init', 'demo_register_post_type');
  2.  
  3. function demo_register_post_type() {
  4.     register_post_type('tribe_events', array( 'rewrite' => array('slug' => 'event', 'with_front' => false),
  5.         'labels' => array(
  6.             'name' => 'Demos',
  7.             'singular_name' => 'Demo',
  8.             'add_new' => 'Add new demo',
  9.             'edit_item' => 'Edit demo',
  10.             'new_item' => 'New demo',
  11.             'view_item' => 'View demo',
  12.             'search_items' => 'Search demos',
  13.             'not_found' => 'No demos found',
  14.             'not_found_in_trash' => 'No demos found in Trash'
  15.         ),
  16.         'public' => true,
  17.         'supports' => array(
  18.             'title',
  19.             'excerpt'
  20.         ),
  21.         'taxonomies' => array('category', 'post_tag') // this is IMPORTANT
  22.     ));
  23. }
  24.  
  25.  
  26. add_filter('pre_get_posts', 'query_post_type');
  27. function query_post_type($query) {
  28.   if(is_archive() || is_tag() || is_home() && empty( $query->query_vars['suppress_filters'] ) ) {
  29.     $post_type = get_query_var('post_type');
  30.         if($post_type)
  31.             $post_type = $post_type;
  32.         else
  33.             $post_type = array('post','tribe_events','attachment');
  34.     $query->set('post_type',$post_type);
  35.         return $query;
  36.     }
  37. }
  38.  
  39.  
  40.