I got a function that automaticly creates a custom field in the post. I have this located in my functions.php.
Image
is the name of the custom field and HERE
is the value. How can I put the function w_thumbnail_src
as the variable?
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;
}
and let me add that w_thumbnail_src
is a function in the same file that looks like this
function w_thumbnail_src() {
if (has_post_thumbnail()) {
$thumb = wp_get_attachment_image_src(get_post_thumbnail_id(), 'emphasis');
echo $thumb[0]; // thumbnail url
}
}
I think you need to change:
add_post_meta($post_id, 'Image','HERE', true);
to:
add_post_meta($post_id, 'Image', w_thumbnail_src(), true);
And also fix the w_thumbnail_src() function by changing it to the following:
Here is the final code that adds the thumbnail url to a custom field named Image.