• I need to populate a custom field with the post id.
    The custom field is called ID_item, and up until now i have been using the post title for this field, typed in manually when each post is published. As this field needs to be 100% unique for each post, it makes sense to use the post id instead.

    To start with i need to change this for the 800 existing posts.

    I am new to SQL, in phpMyAdmin this brings up the required fields:

    SELECT *
    FROM wp_postmeta
    WHERE meta_key LIKE ‘ID_item’

    Now i need to copy the post_id into the meta_value column (overwriting its existing contents) for the displayed results, and im lost.

    Any help greatly appreciated.

    PS encase you are wondering why i dont just adjust the theme to query post_id where it currently queries ID_item, its a bloody complicated e-commerce theme.

  • The topic ‘Populate a custom field with post ID in sql and or php function’ is closed to new replies.