Hello I'm wondering if anyone can help me figure this out. Essentially when I click on my custom post type 'Portfolio' in admin, I see a list of 'Services' next to posts, but when I click on one to filter (e.g. http://localhost:8888/wp-admin/edit.php?post_type=portfolio&Service=web-design
) nothing happens! It still lists all taxonomies.
Below is code used to register custom post type & taxonomy (apologies for length, but can't work out what is wrong):
add_action('init','portfolio_register');
function portfolio_register(){
$labels=array(
'name'=> _x('Portfolio','posttype general name'),
'singular_name'=> _x('Project','posttype singular name'),
'add_new'=> _x('Add New Project','portfolio item'),
'add_new_item'=> __('Add New Project'),
'edit_item'=> __('Edit Project'),
'new_item'=> __('New Project'),
'view_item'=> __('View Project'),
'search_items'=> __('Search Portfolio'),
'not_found'=> __('Nothing found'),
'not_found_in_trash'=> __('Nothing found in Trash'),
'parent_item_colon'=>'');
$args=array(
'labels'=>$labels,
'public'=>true,
'publicly_queryable'=>true,
'show_ui'=>true,
'show_in_menu'=>true,
'menu_position'=>5,
'query_var'=>true,
'menu_icon'=> get_stylesheet_directory_uri().'/images/mag.png',
'rewrite'=>true,'capability_type'=>'post',
'hierarchical'=>false,
'supports'=>array('title','editor','thumbnail','comments'));
register_post_type('portfolio',$args);}
register_taxonomy("Service",array("portfolio"),array("hierarchical"=>true,"label"=>"Service","singular_label"=>"Service","rewrite"=>true));
Then to view columns in admin:
add_filter( 'manage_edit-portfolio_columns', 'my_edit_portfolio_columns' ) ;
function my_edit_portfolio_columns( $columns ) {
$columns = array(
'cb' => '<input type="checkbox" />',
'title' => __( 'Project' ),
'Service' => __( 'Services' ),
'date' => __( 'Date' )
);
return $columns;
}
add_action( 'manage_portfolio_posts_custom_column', 'my_manage_portfolio_columns', 10, 2 );
function my_manage_portfolio_columns( $column, $post_id ) {
global $post;
switch( $column ) {
/* If displaying the 'service' column. */
case 'Service' :
/* Get the genres for the post. */
$terms = get_the_terms( $post_id, 'Service' );
/* If terms were found. */
if ( !empty( $terms ) ) {
$out = array();
/* Loop through each term, linking to the 'edit posts' page for the specific term. */
foreach ( $terms as $term ) {
$out[] = sprintf( '<a href="%s">%s</a>',
esc_url( add_query_arg( array( 'post_type' => $post->post_type, 'Service' => $term->slug ), 'edit.php' ) ),
esc_html( sanitize_term_field( 'name', $term->name, $term->term_id, 'Service', 'display' ) )
);
}
/* Join the terms, separating them with a comma. */
echo join( ', ', $out );
}
/* If no terms were found, output a default message. */
else {
_e( 'No Services' );
}
break;
/* Just break out of the switch statement for everything else. */
default :
break;
}
}