Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jonathanfann/8a881235d954b8890c56959ca2088461 to your computer and use it in GitHub Desktop.
Save jonathanfann/8a881235d954b8890c56959ca2088461 to your computer and use it in GitHub Desktop.
Custom Taxonomy added to custom post type (add to functions.php)
<?php
/*
add this to your functions.php
replace 'mytax' with your custom taxonomy
replace 'mypost' with your custom post type
*/
/* 1. add mytax to mypost */
function set_custom_columns($columns) {
$columns['mytax'] = __( 'My Tax Name', 'your_text_domain' );
return $columns;
}
add_filter( 'manage_mypost_posts_columns', 'set_custom_columns' );
/* 2. add to the column */
function custom_column( $column, $post_id ) {
switch ( $column ) {
case 'mytax' :
$terms = get_the_term_list( $post_id , 'mytax' , '' , ',' , '' );
if ( is_string( $terms ) )
echo $terms;
else
_e( 'Unable to get your taxonomy', 'your_text_domain' );
break;
}
}
add_action( 'manage_mypost_posts_custom_column' , 'custom_column', 10, 2 );
/* 3. make it sortable */
function sortable_release_column( $columns ) {
$columns['mytax'] = 'My Tax Name';
return $columns;
}
add_filter( 'manage_edit-press-and-news_sortable_columns', 'sortable_release_column' );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment