我有一个函数在帖子中自动创建一个自定义字段。我有这个位于我的functions.php。在函数中包含w_thumbnail_src?
Image
是自定义字段的名称,HERE
是值。我怎样才能把功能w_thumbnail_src
作为变量?
add_action('wp_insert_post', 'mk_set_default_custom_fields');
function mk_set_default_custom_fields($post_id)
{
if ($_GET['post_type'] != 'post') {
add_post_meta($post_id, 'Image','HERE', true);
}
return true;
}
,让我补充一点,w_thumbnail_src
是看起来像这样
function w_thumbnail_src() {
if (has_post_thumbnail()) {
$thumb = wp_get_attachment_image_src(get_post_thumbnail_id(), 'emphasis');
echo $thumb[0]; // thumbnail url
}
}
我不是很清楚你在问什么? 'add_post_meta($ post_id,'Image',w_thumbnail_src(),true);'你是什么意思? – drew010 2012-02-05 20:27:47
多数民众赞成的想法,但我已经尝试过,它不工作。它只是返回一个空的值字段。我需要缩略图网址在那里出现 – Demilio 2012-02-05 21:19:59