基本上,我正在尝试这样做,如果用户登录,所有待处理的帖子都可以投票。一旦获得10多张选票,它将被公布。
好了,不再使用数据库连接,现在使用元键,因此代码已经更改,以显示我现在拥有的内容
<?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
}
?>
以下内容 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);
返回此Array ( [0] => 0 ) Votes: 1
.它应该只说Votes: 0