Support » Developing with WordPress » How do I create a column in the ‘ Post Meta ‘ in PHP or plugin?

  • manoodin

    (@manoodin)


    How do I create a column in the ‘ Post Meta ‘ in PHP or plugin?

    function new_column_postmeta() {
    
    CREATE TABLE IF NOT EXISTS <code>wp_postmeta</code> (
      <code>meta_id</code> bigint(20) unsigned NOT NULL,
      <code>post_id</code> bigint(20) unsigned NOT NULL DEFAULT '0',
      <code>meta_key</code> varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
      <code>meta_value</code> longtext COLLATE utf8mb4_unicode_ci
      <code>new_column</code> longtext COLLATE utf8mb4_unicode_ci
    ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
    
    }

    If anyone can create the function or point me a plugin I would be very grateful!

    • This topic was modified 3 months ago by  manoodin.
    • This topic was modified 3 months ago by  manoodin.
    • This topic was modified 3 months ago by  manoodin.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Joy

    (@joyously)

    Why would you need a new column? The WP code won’t know about it.
    That table is set up to hold whatever data is needed already: key and value, associated with a post.

    Moderator bcworkz

    (@bcworkz)

    Never add columns to WP tables. Future WP updates that involve DB updates will likely fail. Most people find the provided meta data organization usable enough as it is. If your data needs are such that you must have a special column, create your own custom table and join it to the WP tables via object IDs.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.