Support » Fixing WordPress » Adding a custom field to all existing posts

  • Hello,

    I have come across a problem where i need to edit all 100 posts on my blog to have a custom field value.

    How do I edit all post simultaneously, or how do I add a custom field to all posts.

    Any help would be greatly appreciated, otherwise Im going to be editing posts for the rest of my life lol

Viewing 5 replies - 1 through 5 (of 5 total)
  • Do you want to put the same value in all the custom fields, or are they all different?

    same value in all custom fields

    the custom field name would be image_value
    and the value would be {image}

    I found a way to do it. If you can access the MySQL admin interface, you can run the following query on the WP database:

    INSERT INTO wp_postmeta (post_id, meta_key, meta_value)
    SELECT wp_posts.ID, ‘image_value’, ‘{image}’
    FROM wp_posts
    WHERE wp_posts.post_status = ‘publish’;

    The only thing you might need to change is the WHERE condition. The SQL statement as written above will add that custom field to all published posts.

    ambrosite’s SQL worked pefectly. Sure beats adding 230 custom fields by hand. Thanks.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Adding a custom field to all existing posts’ is closed to new replies.