Voting System, database connections?
Basically I'm trying to make it so that all pending posts can be voted on if the user is logged in. once it gets to 10+ votes it will become published.
OK so no longer using database connections and now using Meta Keys, therefore the code has been changed to show what I now have
?php
//if the post is pending show
if(get_post_status() == 'pending') {
//added a post_vote to the wp_posts database for use later
//if the user is logged in show
if ( is_user_logged_in() ) {
add_post_meta( get_the_ID(), 'post_vote', '0', true );
$post_vote = get_post_meta( get_the_ID(), 'post_vote' );
echo 'Votes: ' . print_r( $post_vote);
//form for submit button
echo "form method=\"POST\" action=\"";
echo ''; //code in here for adding 1 to meta
echo "\"";
echo 'input type="button" name="submit" value="+"';
echo '/form';
} else {
echo'Please Sign in to Vote';
}
} else {
// do nothing
}
?
The following
add_post_meta( get_the_ID(), 'post_vote', '0', true );
$post_vote = get_post_meta( get_the_ID(), 'post_vote' );
echo 'Votes: ' . print_r( $post_vote);
Returns this Array ( [0] = 0 ) Votes: 1
.
It should only say Votes: 0