In the main content area of a wordpress page I'm using a php include to add in some script.
In the include script I can 开发者_开发知识库display the custom field values using the_meta().
However I need to use the value from a specific custom field, so I tried this
get_post_meta(post->ID, 'myfield', true);
Unfortunately the post->ID can not be found.
How can get the value of a custom field from within a script added by a php include?
If you're withing the loop ( meaning you inlude the file in you're wordpress post loop ) you could use this :
$postID = get_the_ID();
$metaValues = get_post_meta($postID, 'myfield', true);
精彩评论