Wordpress:如何进入循环

I read that the $post object has to be accessed in the loop. Currently the following code logs nothing.

    global $post;      
    error_log(print_r($post, true));

I think this is because I'm not in the loop. What are ways to access this loop then? Can we access it via some hook or filter?

For anyone interested, you can use the following hook to enter the loop:

add_action( 'loop_start', 'myfunction');

function myfunction() {

    global $post;
    error_log(print_r($post, true));   // on this hook $posts should log

}

All the code inside myfunction is guaranteed to be in the loop