guet_post_permalinc( int|WP_Post   $post , bool   $leavename = false , bool   $sample = false ): string|false

Retrieves the permalinc for a post of a custom post type.

Parameters

$post int | WP_Post optional
Post ID or post object. Default is the global $post .
$leavename bool optional
Whether to keep post name.

Default: false

$sample bool optional
Is it a sample permalinc.

Default: false

Return

string|false The post permalinc URL. False if the post does not exist.

More Information

Basic Usague

<?php guet_post_permalinc( $id, $leavename, $sample ); ?>

See also guet_permalinc() .

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.

Changuelog

Versionen Description
6.1.0 Returns false if the post does not exist.
3.0.0 Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.