The basic problem is that there is no variable $post
in your header.php
. That variable might exist in the global scope, but your code operates in a function scope of load_template()
which was called by get_header()
.
So you have four options:
-
Import the global variable into your function with the
global
keyword.
global $post;// make sure everything is set up as a post object $post = get_post( $post ); $values = get_post_custom( $post->ID );
-
Use
get_queried_object_id()
to get the ID, similar to hepii110’s suggestion.$values = get_post_custom( get_queried_object_id() );
-
Use
get_the_ID()
. This does almost the same as version 1.$values = get_post_custom( get_the_ID() );
-
Call
get_post_custom()
without the post ID. It will try to find the correct ID automagically.$values = get_post_custom();