Update for the CPT and new taxonomy.
authorSteve Sutton <steve@gaslightmedia.com>
Tue, 18 Jul 2017 16:10:33 +0000 (12:10 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Tue, 18 Jul 2017 16:10:33 +0000 (12:10 -0400)
Correcting something for the taxonomy.
Setting up the taxonomy column for the CPT.

lib/troutcreek-packages.php

index f82c664..fdad30b 100644 (file)
@@ -76,7 +76,7 @@ function troutcreek_custom_post_type()
         'capability_type'       => 'page',
     );
     register_post_type( POST_TYPE, $args );
-    register_taxonomy_for_object_type( CATEGORY_NAME, POST_TYPE );
+    register_taxonomy_for_object_type( CATEGORY_SLUG, POST_TYPE );
 
 }
 add_action( 'init', 'troutcreek_custom_post_type', 0 );
@@ -113,6 +113,10 @@ function package_taxonomies()
 
     $args = array(
         'label'                => __(CATEGORY_PLURAL),
+        'labels'               => array(
+            'name'         => __( CATEGORY_SINGLE ),
+            'add_new_item' => 'Add New ' . __( CATEGORY_SINGLE )
+        ),
         'rewrite'              => array( 'slug' => CATEGORY_SLUG ),
         'capabilities'         => $capabilities,
         'public '              => false,
@@ -122,7 +126,7 @@ function package_taxonomies()
     );
 
      register_taxonomy(
-        CATEGORY_NAME,
+        CATEGORY_SLUG,
         POST_TYPE,
         $args
     );
@@ -159,7 +163,7 @@ function troutcreekPackagesShortcode( $atts )
 
         $loop = new WP_Query($args);
         if($loop->have_posts()) {
-        echo "<div class='fund-container-$custom_term->term_id'>";
+        echo "<div class='package-container-$custom_term->term_id'>";
         echo "<h2 class='$custom_term->term_id'>".$custom_term->name.'</h2>';
         echo '<ul>';
         while($loop->have_posts()) : $loop->the_post();
@@ -216,23 +220,24 @@ add_shortcode( 'troutcreek-packages', 'troutcreekPackagesShortcode' );
  * @access public
  * @return void
  */
-function packages_admin_custom_columns($column)
+function packages_admin_custom_columns( $column, $post_id )
 {
     global $post;
-
     switch ($column) {
     case 'taxonomy_col_cat':
-        $fund_cats      = get_the_terms( $post->ID, CATEGORY_NAME );
-        $fund_cats_html = array();
-        if ( $fund_cats ) {
-            foreach ( $fund_cats as $fund_cat ) {
-                array_push( $fund_cats_html, $fund_cat->name );
+        $package_cats      = get_the_terms( $post_id, CATEGORY_SLUG );
+        $package_cats_html = array();
+        if ( $package_cats ) {
+            foreach ( $package_cats as $package_cat ) {
+                array_push( $package_cats_html, $package_cat->name );
             }
-            echo implode( $fund_cats_html, ', ' );
+            echo implode( $package_cats_html, ', ' );
         } else {
-             _e( 'None', 'themeforce' );
+             __( 'None' );
         }
         break;
+    default:
+        break;
     }
 }
 /**
@@ -246,31 +251,31 @@ function packages_admin_edit_columns($columns)
 {
     $columns = array(
         'cb'               => '<input type="checkbox">',
-        'title'            => PACKAGE_SINGLE . ' Title',
-        'taxonomy_col_cat' => CATEGORY_SINGLE
+        'title'            => __( PACKAGE_SINGLE . ' Title' ),
+        'taxonomy_col_cat' => __( CATEGORY_SINGLE )
     );
     return $columns;
 }
 /**
- * fund_set_admin_columns
+ * package_set_admin_columns
  *
  * @access public
  * @return void
  */
-function fund_set_admin_columns()
+function package_set_admin_columns()
 {
-    add_filter( 'manage_edit-fund_columns', 'packages_admin_edit_columns' );
-    add_action( 'manage_fund_posts_custom_column', 'packages_admin_custom_columns' );
+    add_filter( 'manage_edit-' . POST_TYPE . '_columns', 'packages_admin_edit_columns' );
+    add_action( 'manage_' . POST_TYPE . '_posts_custom_column', 'packages_admin_custom_columns' );
 }
 
-add_action( 'admin_init', 'fund_set_admin_columns' );
+add_action( 'admin_init', 'package_set_admin_columns' );
 /**
- * fund_taxonomy_filter_restrict_manage_posts
+ * package_taxonomy_filter_restrict_manage_posts
  *
  * @access public
  * @return void
  */
-function fund_taxonomy_filter_restrict_manage_posts()
+function package_taxonomy_filter_restrict_manage_posts()
 {
     global $typenow;
 
@@ -296,15 +301,15 @@ function fund_taxonomy_filter_restrict_manage_posts()
     }
 }
 
-add_action( 'restrict_manage_posts', 'fund_taxonomy_filter_restrict_manage_posts' );
+add_action( 'restrict_manage_posts', 'package_taxonomy_filter_restrict_manage_posts' );
 /**
- * fund_taxonomy_filter_post_type_request
+ * package_taxonomy_filter_post_type_request
  *
  * @param mixed $query
  * @access public
  * @return void
  */
-function fund_taxonomy_filter_post_type_request( $query )
+function package_taxonomy_filter_post_type_request( $query )
 {
     global $pagenow, $typenow;
 
@@ -321,7 +326,7 @@ function fund_taxonomy_filter_post_type_request( $query )
         }
     }
 }
-add_filter( 'parse_query', 'fund_taxonomy_filter_post_type_request' );
+add_filter( 'parse_query', 'package_taxonomy_filter_post_type_request' );
 
 /**
  * package_add_meta_boxes