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.

How can I change the page that the 'view' action links to on the list post screen for a custom post type?

Update

I've got it to work with normal post types using the below code but where do I define the custom post type?

function change_link($post_url,$post) {
    return '/video?id='.$post->ID;
}
add_filter('post_link',"change_link",10,2);
share|improve this question

2 Answers 2

up vote 2 down vote accepted

By adding a filter to the 'post_link' hook. See the get_permalink() function for more info.

For custom post types, you can use the 'post_type_link' hook.

It's a lot easier if you follow the source code (this is for v3.0):

share|improve this answer
    
Thanks - I'm almost there. I've update my question. –  fxfuture Sep 30 '10 at 0:38
    
See updated answer. –  scribu Oct 6 '10 at 9:28

Based on the update of your question:

function change_link( $permalink, $post ) {
    if( $post->post_type == 'video' ) { // assuming the post type is video
        $permalink = home_url( 'video?id='.$post->ID );
    }
    return $permalink;
}
add_filter('post_type_link',"change_link",10,2);
share|improve this answer
    
I tried that before and it doesn't work. It just removes the permalink altogether for my blog posts (because the filter is still being applied to standard 'posts' but the function's not returning anything) and doesn't change the video custom posts. –  fxfuture Sep 30 '10 at 17:49
1  
I edited my answer. I may have been very tired when I wrote it. :) –  sorich87 Sep 30 '10 at 18:24
    
No problem! Your code works for normal posts if I change ($post->post_type == 'post') but when I use 'video' or another of my custom post types it doesn't work? –  fxfuture Sep 30 '10 at 20:06
    
I'm probably missing something obvious, but why is manipulating the post_link to add a query var for the custom post type even necessary? I've never had to do this - my "view" links (and all other permalinks for that matter) already have the post type inserted in the URL... –  somatic Oct 22 '10 at 17:52
    
He wanted all the videos posts to go to the same page (not to their default page) and the post id passed in the URL. E.g.: mysite.com/video?id=23, mysite.com/video?id=54, etc. –  sorich87 Oct 22 '10 at 18:18

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.