Created
October 1, 2013 08:39
-
-
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/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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" ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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