• Hello,

    I recently changed the theme i use to my site and in the new one I use thumbnails on the home page next to each post. To do so, there is a certain Custom Key on each post that holds the url of the image.

    So far so good… the problem is that older posts do not have this custom key because i wasn’t using thumbnails. So, how can i automatically add the specific custom key to all the articles, with the first image url found one each article as value?

    Thank you very much on advance!

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter asynadak

    (@asynadak)

    Thank you very much for you time and your reply.

    This plugin is very interesting and useful, but it will only help me with new posts. My site has around 2500 old posts and it requires a lot of time to add a thumbnail to each one of them.

    Every single post has an images on it. So, i want to find the url of this image and store it as a custom key. Can this be done with a plugin or with a piece of code?

    you need to come up with some regex code to extract the filename from <img src=’filename.jpg’ alt=”” />

    and then have a routine that reads all the posts, applies the regex code to each one to extract the filename and write a custom field from it.

    i’m not a regex guy so can’t help you with that code. that is what will accomplish what you are after.

    Thread Starter asynadak

    (@asynadak)

    Thank you for your reply. This is what i was thinking also. Probably i will have to loop through the posts and take the image url.

    Let’s say that somehow i grab the url i need, how can i add a custom key programmatically?

    <?php update_post_meta($post->ID, $meta_key, $meta_value; ?>

    $post->ID will come from the looping through the posts
    $meta_key will be the custom field ‘thumbnail’ or whatever
    $meta_value, from the looping, the extracted filename

    <?php update_post_meta($post->ID, 'thumbnail', $filename; ?>

    Thread Starter asynadak

    (@asynadak)

    This should do the work. Thank you very much!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How to add thumbnails to old posts’ is closed to new replies.