get_post_permalink()
Retrieves the permalink for a post of a custom post type.
Used By: get_permalink()
1 time — 0.000578 sec (slow) | 50000 times — 5 sec (fast)
Hooks from the function
Return
String|false
. The post permalink URL. False if the post does not exist.
Usage
get_post_permalink( $post, $leavename, $sample );
- $post(int|WP_Post)
- Post ID or post object.
Default: global $post - $leavename(true|false)
- Whether to keep post name.
Default: false - $sample(true|false)
- Is it a sample permalink.
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_rewrite WordPress rewrite component.
Changelog
Since 3.0.0 | Introduced. |
Since 6.1.0 | Returns false if the post does not exist. |