开发者

Wordpress - Custom Fields

开发者 https://www.devze.com 2023-02-18 06:30 出处:网络
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().

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消