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 can get the permalink of a specific post tag or category, but what if I want to get the permalink of a custom post type? I can't find anything in the Codex or anywhere else about how to do this.

share|improve this question
add comment

5 Answers

up vote 4 down vote accepted

How about <?php get_post_type_archive_link( $post_type ); ?>, where $post_type is your post type?

Further reading: Codex

share|improve this answer
add comment

I know this post might be old but just in case someone else is searching the function that does this, here's the one i wrote. $post_type must be passed as a variable :)

if( !function_exists( 'wp_get_post_type_link' )  ){
    function wp_get_post_type_link( &$post_type ){

        global $wp_rewrite; 

        if ( ! $post_type_obj = get_post_type_object( $post_type ) )
            return false;

        if ( get_option( 'permalink_structure' ) && is_array( $post_type_obj->rewrite ) ) {

            $struct = $post_type_obj->rewrite['slug'] ;
            if ( $post_type_obj->rewrite['with_front'] )
                $struct = $wp_rewrite->front . $struct;
            else
                $struct = $wp_rewrite->root . $struct;

            $link = home_url( user_trailingslashit( $struct, 'post_type_archive' ) );       

        } else {
            $link = home_url( '?post_type=' . $post_type );
        }

        return apply_filters( 'the_permalink', $link );
    }
}

Hope it helps ! :)

share|improve this answer
add comment

Within the loop, you can simply use the_permalink(). Outside of the loop, you can use get_permalink( $id ).

share|improve this answer
    
That returns the permalink of a specific post or page. I want to return the permalink of a post type. So, for instance, if there is a post type called "movie reviews", and the permalink of that post type is "www.website.com/movie-reviews", how do I get that permalink? Maybe this is not a true permalink technically, I just want the URL of that post type. –  Industrial Themes Oct 25 '11 at 12:48
add comment

yeah I think you need to display link to display somewhere on site then you need to pass echo get_bloginfo('url')/movie-reviews

share|improve this answer
add comment

Or, for what it's worth, get_term_link($term, $taxonomy); - Codex.

share|improve this answer
add comment

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.