Skip to content

Instantly share code, notes, and snippets.

@spencejs
Last active December 15, 2015 06:49
Show Gist options
  • Select an option

  • Save spencejs/5218997 to your computer and use it in GitHub Desktop.

Select an option

Save spencejs/5218997 to your computer and use it in GitHub Desktop.
Add Custom Taxonomy Admin Column In Wordpress
////////////////////////////////////////////////
//Add Project Type Column to Projects Backend
///////////////////////////////////////////////
add_filter('manage_edit-project_columns', 'project_columns');
function project_columns($columns) {
unset($columns['date']);
$columns['Type'] = 'Type';
$columns['date'] = 'Date';
return $columns;
}
add_action('manage_posts_custom_column', 'project_show_columns');
function project_show_columns($name) {
global $post;
switch ($name) {
case 'Type':
//Fancy Code to Get List with Admin Filter Links
$taxonomy = 'project_types';
$taxonomy_object = get_taxonomy( $taxonomy );
$object_type = get_post_type($post_id);
if ( $terms = get_the_terms( $post_id, $taxonomy ) ) {
$out = array();
foreach ( $terms as $t ) {
$posts_in_term_qv = array();
$posts_in_term_qv['post_type'] = $object_type;
if ( $taxonomy_object->query_var ) {
$posts_in_term_qv[ $taxonomy_object->query_var ] = $t->slug;
} else {
$posts_in_term_qv['taxonomy'] = $taxonomy;
$posts_in_term_qv['term'] = $t->slug;
}
$out[] = sprintf( '<a href="%s">%s</a>',
esc_url( add_query_arg( $posts_in_term_qv, 'edit.php' ) ),
esc_html( sanitize_term_field( 'name', $t->name, $t->term_id, $taxonomy, 'display' ) )
);
}
/* translators: used between list items, there is a space after the comma */
echo join( __( ', ' ), $out );
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment