WordPress.org

Ready to get started?Download WordPress

Forums

Adding a custom field to all existing posts (6 posts)

  1. reefchronicle
    Member
    Posted 4 years ago #

    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

  2. ambrosite
    Member
    Posted 4 years ago #

    Do you want to put the same value in all the custom fields, or are they all different?

  3. reefchronicle
    Member
    Posted 4 years ago #

    same value in all custom fields

  4. reefchronicle
    Member
    Posted 4 years ago #

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

  5. ambrosite
    Member
    Posted 4 years ago #

    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.

  6. yitwail
    Member
    Posted 3 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic