How can I add a column/s to wp_posts table?

You can technically add a post column with SQL but I’d caution against it as backup scripts, exports etc. would likely ignore it.

Instead, I would add the content as a post_meta, either using a Custom Field or through PHP with the update_post_meta() function.

To fetch a post based on the meta simply use:

$args = array(
        'post_type' => 'custom_post_type',
        'meta_key' => 'api',
        'meta_value' => $api_value,
      );
$posts = get_posts( $args )

or, to fetch the value of the API key

get_post_meta( $post_ID, 'api', true );

Leave a Comment