WordPress.org

Ready to get started?Download WordPress

Forums

Custom Post Type Taxonomy Display (5 posts)

  1. fitJaime
    Member
    Posted 3 years ago #

    I need to display the categories for my custom post type in the Dashboard.

    I have this code:

    function business_edit_columns($business_columns) {
    		$new_columns['cb'] = '<input type="checkbox" />';
    
    		$new_columns['title'] = _x('Business Name', 'column name');
    		$new_columns['author'] = __('Author');
    
    		$new_columns['categories'] = __('Categories');
    
    		$new_columns['date'] = _x('Date', 'column name');
    
    		return $new_columns;
    	}

    And the categories are displaying "Uncategorized" instead of the custom taxonomy that is associated with the business listing. I think I'm in need of another function to tell WP what I'm after (since it's a custom taxonomy, not a standard one)

    I had thought something like:

    function business_columns_display($business_columns){
    	switch ($business_columns)
    	{
    		case "categories":
    			get_the_terms($post->ID, 'bz_categories',);
    			break;
    	}
    }

    Might be the answer, but since I'm not in the loop, that doesn't work.

    Thanks!

  2. division84
    Member
    Posted 2 years ago #

    function add_new_gallery_columns($gallery_columns) {
    		$new_columns['cb'] = '<input type="checkbox" />';
    		$new_columns['title'] = __('Title');;
    		$new_columns['author'] = __('Author');
    		$new_columns['specs_'.$_GET['post_type']] = __('Categories');
    		//$new_columns['tags'] = __('Tags');
    		$new_columns['date'] = _x('Date', 'column name');
    
    		return $new_columns;
    	}
    
    add_action( 'manage_posts_custom_column' , 'custom_columns' );
    
    function custom_columns( $column ) {
    
    	global $post;
    
    	switch ( $column )
    	{
    		case 'specs_health':
    			$terms = get_the_term_list( $post->ID , 'specs_health' , '' , ',' , '' );
    			if ( is_string( $terms ) ) {
    				echo $terms;
    			}
    			else
    			{
    				echo 'Please Put In A Category';
    			}
    
    			break;
    		case 'specs_lifestyle':
    			$terms = get_the_term_list( $post->ID , 'specs_lifestyle' , '' , ',' , '' );
    			if ( is_string( $terms ) ) {
    				echo $terms;
    			}
    			else
    			{
    				echo 'Please Put In A Category';
    			}
    
    			break;
    		case 'specs_relationships':
    			$terms = get_the_term_list( $post->ID , 'specs_relationships' , '' , ',' , '' );
    			if ( is_string( $terms ) ) {
    				echo $terms;
    			}
    			else
    			{
    				echo 'Please Put In A Category';
    			}
    
    			break;
    		case 'specs_entertainment':
    			$terms = get_the_term_list( $post->ID , 'specs_entertainment' , '' , ',' , '' );
    			if ( is_string( $terms ) ) {
    				echo $terms;
    			}
    			else
    			{
    				echo 'Please Put In A Category';
    			}
    
    			break;
    	}
    }

    This worked for me like a charm. The "specs_whatever" are the names of my custom taxonomies.

  3. shafraz
    Member
    Posted 2 years ago #

    hi ssjaime.
    try this code its workin for me no problems at all.

    add_action( 'right_now_content_table_end' , 'ucc_right_now_content_table_end' );
    
    function ucc_right_now_content_table_end() {
      $args = array(
        'public' => true ,
        '_builtin' => false
      );
      $output = 'object';
      $operator = 'and';
    
      $tag_types = get_taxonomies( $args , $output , $operator );
    
      foreach( $tag_types as $tag_type ) {
    
    	  $terms = get_terms($tag_type->name);
     		$num = count($terms);
    
      //  $num_posts = wp_count_posts( $tag_type->name );
      //  $num = number_format_i18n( $num_posts->publish );
        $text = _n( $tag_type->labels->singular_name, $tag_type->labels->name , intval( $num_posts->publish ) );
        if ( current_user_can( 'edit_posts' ) ) {
          $num = "<a href='edit-tags.php?taxonomy=$tag_type->name'>$num</a>";
          $text = "<a href='edit-tags.php?taxonomy=$tag_type->name'>$text</a>";
        }
        echo '<tr><td class="first b b-' . $tag_type->name . '">' . $num . '</td>';
        echo '<td class="t ' . $tag_type->name . '">' . $text . '</td></tr>';
      }
    
    }
  4. shafraz
    Member
    Posted 2 years ago #

    And if you want to show custom post types also past this code also with the previous one in you function.php

    add_action( 'right_now_content_table_end' , 'ucc_right_now_content_table_end2' );
    
    function ucc_right_now_content_table_end2() {
      $args = array(
        'public' => true ,
        '_builtin' => false
      );
      $output = 'object';
      $operator = 'and';
    
      $post_types = get_post_types( $args , $output , $operator );
    
      foreach( $post_types as $post_type ) {
        $num_posts = wp_count_posts( $post_type->name );
        $num = number_format_i18n( $num_posts->publish );
        $text = _n( $post_type->labels->singular_name, $post_type->labels->name , intval( $num_posts->publish ) );
        if ( current_user_can( 'edit_posts' ) ) {
          $num = "<a href='edit.php?post_type=$post_type->name'>$num</a>";
          $text = "<a href='edit.php?post_type=$post_type->name'>$text</a>";
        }
        echo '<tr><td class="first b b-' . $post_type->name . '">' . $num . '</td>';
        echo '<td class="t ' . $post_type->name . '">' . $text . '</td></tr>';
      }
    
    }
  5. Bev
    Member
    Posted 2 years ago #

    Excellent, thanks shafraz!

Topic Closed

This topic has been closed to new replies.

About this Topic