Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Plugin API/Filter Reference/post type link


post_type_link is a filter applied to the permalink URL for a post or custom post type prior to being returned by the function get_post_permalink.


(string) (required) The post URL
Default: None
(object) (optional) The post object
Default: None
(bool) (optional) Whether to keep the post name
Default: false
(bool) (optional) Is it a sample permalink?
Default: false


Append the query string for the custom post type 'my_custom_post_type' permalink URLs (uses add_query_arg and get_post_type):

function append_query_string( $url, $post ) {
    if ( 'my_custom_post_type' == get_post_type( $post ) ) {
        return add_query_arg( $_GET, $url );
    return $url;
add_filter( 'post_type_link', 'append_query_string', 10, 2 );

Change Log

Source Files

This filter is applied by:


This article is marked as in need of editing. You can help Codex by editing it.