get_post_permalink [ WordPress Function ]
get_post_permalink ( $id = 0, $leavename = false, $sample = false )
| Parameters: |
|
| Returns: |
|
| Defined at: |
|
Soorgelijke functies: post_permalink, get_post_format_link, get_permalink, get_blog_permalink, get_sample_permalink
Retrieve the permalink for a post with a custom post type.
Source
<?php
function get_post_permalink( $id = 0, $leavename = false, $sample = false ) {
global $wp_rewrite;
$post = &get_post($id);
if ( is_wp_error( $post ) )
return $post;
$post_link = $wp_rewrite->get_extra_permastruct($post->post_type);
$slug = $post->post_name;
$draft_or_pending = isset($post->post_status) && in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft' ) );
$post_type = get_post_type_object($post->post_type);
if ( !empty($post_link) && ( !$draft_or_pending || $sample ) ) {
if ( ! $leavename ) {
if ( $post_type->hierarchical )
$slug = get_page_uri($id);
$post_link = str_replace("%$post->post_type%", $slug, $post_link);
}
$post_link = home_url( user_trailingslashit($post_link) );
} else {
if ( $post_type->query_var && ( isset($post->post_status) && !$draft_or_pending ) )
$post_link = add_query_arg($post_type->query_var, $slug, '');
else
$post_link = add_query_arg(array('post_type' => $post->post_type, 'p' => $post->ID), '');
$post_link = home_url($post_link);
}
return apply_filters('post_type_link', $post_link, $post, $leavename, $sample);
}
?>
Examples [ wp-snippets.com ]
Top Google zoekresultaten
- Function Reference/get post permalink « WordPress Codex
Description. The get_post_permalink template tag retrieves the permalink for a post with a custom post type. Usage. <?php get_post_permalink( $id ...
codex.wordpress.org - #14294 (get_permalink() calling get_post_permalink() with post ...
It appears that get_permalink() in WP 3.0 (/wp-includes/link-template.php line 111) is calling get_post_permalink() with a post object instead of post ID as the first ...
core.trac.wordpress.org - #14299 (get_post_permalink incorrect documentation and variable ...
Should always be a post object, so we can use the same callbacks we have on post_link. That's how I discovered this issue: I was about to create a new callback ...
core.trac.wordpress.org - get_post_permalink | A HitchHackers guide through WordPress
Feb 12, 2011 ... function get_post_permalink( $id = 0, $leavename = false, $sample = false ) { global $wp_rewrite; $post = &get_post($id); if ( is_wp_error( ...
hitchhackerguide.com