I'm writing new theme for my blog. And I want to make some kind of post rating using custom fields.
There are two fields: 'good-post' and 'bad-post'. And after each post I placed two buttons. Yep, 'Good post' and 'Bad post'. On buttons I placed onclick event that calls this AJAX function:
function ajaxIncGoodPost(tempUrl) {
var postID = $("good-post").attr("rel");
jQuery.ajax({
type: "POST",
url : tempUrl+"/rating.php",
data: "opinion=good&postID="+postID,
success: function(msg){
alert( "Спасибо за вашу хорошую оценку!" );
}
});
}
It calls this function in rating.php
:
$postID = $_REQUEST['postID'];
if ( $_REQUEST['opinion'] == 'good' ) {
$good_post = get_post_meta($postID, 'good-post');
function inc_good_post() {
$good_post++;
update_post_meta($postID, 'good-post', $good_post);
}
}
So every click on this button calls function that increments 'good-post'
value and stores it in the field. But here comes the problem. After click on the button success messege of AJAX function pops up, but value of custom field doesn't changes.
I thought this happens because there is no such fields in my old posts, but according to Wordpress Codex upadate_post_meta()
checks if such field exists and if not calls add_post_meta()
which creates field. But this doesn't heepen either.
At this point I can't find any mistake. If you have any guesses about this problem please share it!