Voting System, database connections?

What you want are post meta/custom fields, using these functions:

  • get_post_meta
  • add_post_meta
  • update_post_meta

Adding a new column to the posts table will only cause further issues down the line e.g.:

  • database schema changes in WP Core destroying your extra column
  • having to write your own custom SQL for everything related to post votes
  • No help from WP_Query, object caches, and caching plugins
  • No import/export support
  • All post types will have the voting column, do you need voting data on attachments, post revisions, and pages?

E.g.

update_post_meta(76, 'my_key', 'Steve');

Will update/save a ‘my_key’ meta value of ‘steve’ to post 76, which we can then retrieve later on using:

echo get_post_meta( 76, 'my_key', true );

There is a similar meta API for users and comments