Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

share|improve this question
    
are you sure that 'url' is the name of the field and that it has any content? –  Bainternet Mar 6 '12 at 11:08
1  
Why not get_permalink( $post_id );? –  toscho Mar 6 '12 at 11:19
    
I swore I tried that.. but it was 3:30 am. I just replaced the get_post_meta with the get_permalink and it worked. I think when I tried that I had forgotten to call the global $post variable. Thanks! –  krazymatty Mar 6 '12 at 20:56
    
Okay, then I move my comment to an answer. :) –  toscho Mar 6 '12 at 23:17

1 Answer 1

up vote 1 down vote accepted

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().

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.