0

So I migrated a website of a webdesigner and he used for news-posts a custom field for images. Now I made this website and I need to change 256 posts to set a featured image since it's not working with this custom field. Does anyone know how to set a post featured image from an already made custom field?

0

Your question is not entirely clear, but I suppose your new theme is using featured images in the normal way, which leaves empty featured images on older posts, because they are stored in a custom field. You can catch those using the filter at the end of get_the_post_thumbnail. Because I don't know how the custom field is made I can't give complete code, but it would look like this:

add_filter ('post_thumbnail_html','wpse303106_custom_featured_image',10,5);

function wpse303106_custom_featured_image ($html, $post->ID, $post_thumbnail_id, $size, $attr) {
  if ('' == $html && test-for-existence-of-custom-field) {
    $html = ... assemble from custom field ...
    }
  return $html;
  }
2
  • Can't speak dutch in here right? well this is the old website: vledder.nu/category/nieuws I dont even know what custom field it's using. Underneath 'Nieuws' there are different images, I need the images on the left of the news as the new featured image in the posts for example. – mel May 9 '18 at 13:59
  • From the site I can't see the code that is generating the custom field. You'll have to ask the old developer. Building the filter shouldn't be more than 15 minutes work or so. – cjbj May 9 '18 at 14:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.