WordPress.org

Support

Support » Alpha/Beta » [Resolved] Custom Categories and Tags Doesnt Show Up

[Resolved] Custom Categories and Tags Doesnt Show Up

  • i use custom taxonomies for category and tag in my custom post type. but the categories and tags doesnt show up in post list.

Viewing 1 replies (of 1 total)
  • get it done already. here my code. free to use 🙂

    @t31os_ very much thanks to you. managed to get it done with your help. really happy to share my code to whoever want to have custom categories and tags to be displayed like normal post list.

    function product_columns($posts_columns) {
    	$posts_columns = array();
    	$posts_columns['cb'] = '<input type="checkbox" />';
    	$posts_columns['title'] = _x('Title', 'column name');
    	$posts_columns['author'] = __('Author');
    	if ( empty($post_type) || is_object_in_taxonomy($post_type, 'category') )
    		$posts_columns['product_categories'] = __('Categories');
    	if ( empty($post_type) || is_object_in_taxonomy($post_type, 'post_tag') )
    		$posts_columns['product_tags'] = __('Tags');
    	$post_status = !empty($_REQUEST['post_status']) ? $_REQUEST['post_status'] : 'all';
    	if ( !in_array( $post_status, array('pending', 'draft', 'future') ) && ( empty($post_type) || post_type_supports($post_type, 'comments') ) )
    		$posts_columns['comments'] = '<div class="vers"><img alt="Comments" src="' . esc_url( admin_url( 'images/comment-grey-bubble.png' ) ) . '" /></div>';
    	$posts_columns['date'] = __('Date');
    
    	return $posts_columns;
    }	
    
    function product_data_columns( $column_name) {
    		switch ($column_name) {
    		case 'product_categories':
    		$_taxonomy = 'product_category';
    		$categories = get_the_terms( $post_id, $_taxonomy );
    		if ( !empty( $categories ) ) {
    			$out = array();
    			foreach ( $categories as $c )
    				$out[] = "<a href='edit.php?product_category=$c->slug&post_type=product'> " . esc_html(sanitize_term_field('name', $c->name, $c->term_id, 'category', 'display')) . "</a>";
    			echo join( ', ', $out );
    		}
    		else {
    			_e('Uncategorized');
    		}
    		break;
    
    		case 'product_tags':
    		$_taxonomy = 'product_tag';
    		$tags = get_the_terms( $post_id, $_taxonomy );
    		if ( !empty( $tags ) ) {
    			$out = array();
    			foreach ( $tags as $c )
    				$out[] = "<a href='edit.php?product_tag=$c->slug&post_type=product'> " . esc_html(sanitize_term_field('name', $c->name, $c->term_id, 'post_type', 'display')) . "</a>";
    				echo join( ', ', $out );
    		}
    		else {
    			_e(' No Tags');
    		}
    		break;
    	}
    }
    add_filter( 'manage_product_posts_columns', 'product_columns' );
    add_action( 'manage_posts_custom_column', 'product_data_columns', 10, 2 );

    just like t31os_ code here, most of it i copied from template.php and make minor adjustment to reflect my custom taxonomies.

Viewing 1 replies (of 1 total)
  • The topic ‘[Resolved] Custom Categories and Tags Doesnt Show Up’ is closed to new replies.