php - 在setcookie之后获取cookie

Notice: Undefined index: posts_notification while it's set.

functions.php :

add_action( 'init', 'my_setcookie_example' );
function my_setcookie_example() {
    if (!isset($_COOKIE['posts_notification'])){
        setcookie( 'posts_notification', 'value', time() + 60,COOKIEPATH, COOKIE_DOMAIN);
    }
}

print_r($_COOKIE['posts_notification'] );

I should refresh 2 time to get this value !!!

You need to check cookie first.

if (isset($_COOKIE['posts_notification'])) {
    print_r($_COOKIE['posts_notification'] );
}