I’m trying to add a column to the manage screen that displays the Title and url of the post. I got the Title to work but it’s not pulling the url. Basically I just want to show the url that’s not been cut of like what sometimes happens in the edit screen. Here’s my code:
function change_columns( $cols ) {
$cols = array(
'cb' => '<input type="checkbox" />',
'title' => __( 'Title'),
'url' => __( 'URL', 'trans' ),
);
return $cols;
}
add_filter( "manage_cf-link_posts_columns", "change_columns" );
function custom_columns( $column, $post_id ) {
global $post;
switch ( $column ) {
case "url":
$url = get_post_meta( $post_id, 'url', true);
echo '<a href="' . $url . '">' . $url. '</a>';
break;
}
}
add_action( "manage_cf-link_posts_custom_column", "custom_columns", 10, 2 );
Any help in the right direction is much appreciated.
Thanks,
Phil
1 Answer
Always use get_permalink( $post_id )
to get the URI of a post. It takes care of changed permalink structures and SSL.
Be aware that the similar named function the_permalink()
does not accept a parameter. To get the permalink of a custom post type (or a regular post outside of the loop) you have to use get_permalink()
.