Skip to content

Instantly share code, notes, and snippets.

@LunaCodeGirl
Created October 1, 2013 08:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LunaCodeGirl/6775517 to your computer and use it in GitHub Desktop.
Save LunaCodeGirl/6775517 to your computer and use it in GitHub Desktop.
Custom post type admin list pages. From http://yoast.com/custom-post-type-snippets/
// Change the columns for the edit CPT screen
function change_columns( $cols ) {
$cols = array(
'cb' => '<input type="checkbox" />',
'url' => __( 'URL', 'trans' ),
'referrer' => __( 'Referrer', 'trans' ),
'host' => __( 'Host', 'trans' ),
);
return $cols;
}
add_filter( "manage_<CPT>_posts_columns", "change_columns" );
function custom_columns( $column, $post_id ) {
switch ( $column ) {
case "url":
$url = get_post_meta( $post_id, 'url', true);
echo '<a href="' . $url . '">' . $url. '</a>';
break;
case "referrer":
$refer = get_post_meta( $post_id, 'referrer', true);
echo '<a href="' . $refer . '">' . $refer. '</a>';
break;
case "host":
echo get_post_meta( $post_id, 'host', true);
break;
}
}
add_action( "manage_posts_custom_column", "custom_columns", 10, 2 );
// Make these columns sortable
function sortable_columns() {
return array(
'url' => 'url',
'referrer' => 'referrer',
'host' => 'host'
);
}
add_filter( "manage_edit-<CPT>_sortable_columns", "sortable_columns" );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment