get_post_permalink()
Gets the URL (permalink) of a custom post type.
Instead of this function, a more universal function get_permalink() is usually used. This function is the basis for the function get_permalink().
Used By: get_permalink()
1 time — 0.000578 sec (slow) | 50000 times — 5 sec (fast)
Hooks from the function
Returns
String|false. The post URL. false if the post does not exist (since WP 6.1).
Usage
get_post_permalink( $id, $leavename, $sample );
- $id(integer)
- ID of the post for which the link needs to be obtained.
Default: ID of the current post that is in the WordPress loop at the moment - $leavename(boolean)
- Whether to leave the post name. true - do not replace the placeholder
%post_type%with the post name.
Default: false - $sample(boolean)
- true — this is a sample (example) link. It does not affect the output but is passed to the hook post_type_link.
Default: false
Examples
#1 Display post types URLs
Let's display URLs of different post types and with different parameters.
// built-in post type echo get_post_permalink( 1 ); // https://example.com/?post_type=post&p=1 // URL to custom post type echo get_post_permalink( 225 ); // http://example.com/function/get_permalink echo get_post_permalink( 225, true ); // http://example.com/function/%func%
#2 More Examples
See get_permalink() - wrapper function for this function.
Notes
- Global. WP_Rewrite.
$wp_rewriteWordPress rewrite component.
Changelog
| Since 3.0.0 | Introduced. |
| Since 6.1.0 | Returns false if the post does not exist. |