Insert value in table when new post is created. (3 posts)

  1. nemci7v
    Posted 5 years ago #

    Good day everyone! Hope you're having a great weekend. :) I'm having fun as usual with WordPress.

    I'm working on a personal plugin for voting posts up or down. I'm disallowing visitors to vote more than once by storing their IP addresses. I created 2 new tables in my WordPress database.

    The first one stores IPs

    id (primary auto-increment)
    post_id (id of voted post)
    vote_ip (the voters IP address)

    And the second table shows how many votes each post has.

    id (primary auto-increment)

    Instead of making the POST_VOTES table I could have just added "up", and "down" rows in the default wp Post table but I want to keep the votes separate.

    When I publish a new article in wp, is there a way to add it's post id into the post_votes table? I'm trying to figure out if I can add a function to the plugin file for this rather than editing any core files. This is way beyond me, I would really appreciate some help!

  2. nemci7v
    Posted 5 years ago #

    bump :(

  3. nemci7v
    Posted 5 years ago #

    Sorry to be so persistent.. In general my question is, how to add data to a table other than the default "wp_posts" when publishing a new post.

Topic Closed

This topic has been closed to new replies.

About this Topic