title: How to set default taxonomy (category) for custom post types in WP
body: <p>I have read through every blog post I could find, but nothing out there seems to work for me. All I would need to do is to have WP automatically assign a default taxonomy/category ("newest") to my custom post type "photos", so that when a user adds a new photo, the "newest" category is already selected and assigned (like for the "uncategorised" for a normal blog post).</p>
  
  <pre><code>declare ( encoding = 'UTF-8' );
  
  ! defined( 'ABSPATH' ) and exit;
  
  add_action( 'init', array ( 'MCP_Photos', 'init' ) );
  
  class MCP_Photos
  {
      /**
       * Creates a new instance.
       * 
       * @wp-hook init
       * @see    __construct()
       * @return void
       */
      public static function init()
      {
          new self;
      }
  
      /**
       * Constructor
       */
      public function __construct()
      {
        $labels = array(
      'name' =&gt; 'Photography',
      'singular_name' =&gt; 'Photo',
      'add_new' =&gt; 'Add New',
      'add_new_item' =&gt; 'Add New Photo',
      'edit_item' =&gt; 'Edit Photo',
      'new_item' =&gt; 'New Photo',
      'all_items' =&gt; 'All Photos',
      'view_item' =&gt; 'View Photo',
      'search_items' =&gt; 'Search Photos',
      'not_found' =&gt;  'No Photos found',
      'not_found_in_trash' =&gt; 'No Photos found in Trash', 
      'parent_item_colon' =&gt; '',
      'menu_name' =&gt; 'Photography'
    );
  
          $args = array(
      'labels' =&gt; $labels,
      'public' =&gt; true,
      'publicly_queryable' =&gt; true,
      'show_ui' =&gt; true, 
      'show_in_menu' =&gt; true, 
      'query_var' =&gt; true,
              'rewrite' =&gt; array(
                  'with_front' =&gt; false,
                  'slug' =&gt; "photo"
              ),
       'capability_type' =&gt; 'post',
      'has_archive' =&gt; true, 
      'hierarchical' =&gt; true,
      'menu_position' =&gt; null,
      'supports' =&gt; array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' ),
      'taxonomies' =&gt; array('post_tag')
          );
          register_post_type("photos", $args);
  
          // Prevent WordPress from sending a 404 for our new perma structure.
          add_rewrite_rule(
          '^photo/(\d+)/[^/]+/?$',
          'index.php?post_type=photos&amp;p=$matches[1]',
          'top'
          );
  
          // Inject our custom structure.
          add_filter( 'post_type_link', array ( $this, 'fix_permalink' ), 1, 2 );
      }
  
      /**
       * Filter permalink construction.
       * 
       * @wp-hook post_type_link
       * @param  string $post_link default link.
       * @param  int    $id Post ID
       * @return string
       */
      public function fix_permalink( $post_link, $id = 0 )
      {
          $post = &amp;get_post($id);
          if ( is_wp_error($post) || $post-&gt;post_type != 'photos' )
          {
              return $post_link;
          }
          // preview
          empty ( $post-&gt;slug )
              and $post-&gt;slug = sanitize_title_with_dashes( $post-&gt;post_title );
  
          return home_url(
              user_trailingslashit( "photo/$post-&gt;ID/$post-&gt;slug" )
          );
      }
  }
  
  
  
  // ----------------------------- add photography categories taxonomy ---------------------------------- 
  
  
  function create_photo_categories() {
      register_taxonomy(
          'photography', // name of the taxonomy
          'photos', // for which post type it applies
          array(
              'labels' =&gt; array(
                  'name' =&gt; 'Categories',
                  'add_new_item' =&gt; 'Add New Category',
                  'new_item_name' =&gt; "New Category"
              ),
              'show_ui' =&gt; true,
              'show_tagcloud' =&gt; false,
              'hierarchical' =&gt; true
          )
      );
  }
  
  add_action( 'init', 'create_photo_categories', 0 );
  </code></pre>