wordpress get post permalink by id code example

Example 1: wordpress get_permalink

// Get post permalink (you can use it inside a wp_query loop)
<?php the_permalink(); ?>
// or
<?php $link = get_the_permalink(); ?>

Example 2: get_the_id wordpress

function get_the_ID() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
    $post = get_post();
    return ! empty( $post ) ? $post->ID : false;
}

Example 3: wp get post content by id

$post_id = 5// example post id
$post_content = get_post($post_id);
$content = $post_content->post_content;
echo apply_filters('the_content',$content);

Tags:

Php Example