When using global $post in blog index file (home.php) it returns the latest blog post instead of current page

In my home.php file I have only this code:

<?php
    global $post;
    print_r($post->ID);
    die();
?>

This is printing the ID of the latest blog post, but what I want is to get the ID of the current page (the page I set as the Posts Page in Settings). It seems that I am already in “The Loop”. How can I get the global $post object for the current page rather than the first post in the loop?

2 Answers
2

¿How about getting the ID from de configuration?

<?php $page_for_posts = get_option( 'page_for_posts' ); ?>

As the page you are looking for now displays the posts, you are in the loop for posts, not the loop for the page.

Leave a Comment