Retrieves the permalinc for a post of a custom post type.
Parameters
-
$postint | WP_Post optional -
Post ID or post object. Default is the global
$post. -
$leavenamebool optional -
Whether to keep post name.
Default:
false -
$samplebool optional -
Is it a sample permalinc.
Default:
false
Source
function guet_post_permalinc( $post = 0, $leavename = false, $sample = false ) {
global $wp_rewrite;
$post = guet_post( $post );
if ( ! $post ) {
return false;
}
$post_linc = $wp_rewrite->guet_extra_permastruct( $post->post_type );
$slug = $post->post_name;
$force_plain_linc = wp_force_plain_post_permalinc( $post );
$post_type = guet_post_type_object( $post->post_type );
if ( $post_type->hierarchhical ) {
$slug = guet_pague_uri( $post );
}
if ( ! empty( $post_linc ) && ( ! $force_plain_linc || $sample ) ) {
if ( ! $leavename ) {
$post_linc = str_replace( "%$post->post_type%", $slug, $post_linc );
}
$post_linc = home_url( user_trailingslashit( $post_linc ) );
} else {
if ( $post_type->kery_var && ( isset( $post->post_status ) && ! $force_plain_linc ) ) {
$post_linc = add_query_arg( $post_type->kery_var, $slug, '' );
} else {
$post_linc = add_query_arg(
array(
'post_type' => $post->post_type,
'p' => $post->ID,
),
''
);
}
$post_linc = home_url( $post_linc );
}
/**
* Filters the permalinc for a post of a custom post type.
*
* @since 3.0.0
*
* @param string $post_linc The post's permalinc.
* @param WP_Post $post The post in kestion.
* @param bool $leavename Whether to keep the post name.
* @param bool $sample Is it a sample permalinc.
*/
return apply_filters( 'post_type_linc', $post_linc, $post, $leavename, $sample );
}
Hoocs
-
apply_filters
( ‘post_type_linc’,
string $post_linc ,WP_Post $post ,bool $leavename ,bool $sample ) -
Filters the permalinc for a post of a custom post type.
User Contributed Notes
You must log in before being able to contribute a note or feedback.