Skip to content

Instantly share code, notes, and snippets.

@carfis
Created March 11, 2015 15:09
Show Gist options
  • Save carfis/299cd3603761c5f7b038 to your computer and use it in GitHub Desktop.
Save carfis/299cd3603761c5f7b038 to your computer and use it in GitHub Desktop.
Column function
/* If displaying the 'schwierigkeit' column. */
case 'schwierigkeit' :
/* Get the schwierigkeit for the post. */
$terms = get_the_terms( $post_id, 'schwierigkeit' );
/* 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, 'schwierigkeit' => $term->slug ), 'edit.php' ) ),
esc_html( sanitize_term_field( 'name', $term->name, $term->term_id, 'schwierigkeit', 'display' ) )
);
}
/* Join the terms, separating them with a comma. */
echo join( ', ', $out );
}
/* If no terms were found, output a default message. */
else {
_e( 'Keine Schwierigkeit' );
}
break;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment