Nulled_Icode, thank you so much for making this plugin public. I’ve never ventured to write a plugin, but you made it so clear and simple I’ve actually understood how to use wp,php,js,sql. I’m now modifying your thank post plugin into a voting plugin – giving people the opportunity to vote YES or NO on a certain post (like a motion to approve something by a board of directors). It’s going good so far.
Once again, thank you for writing clean code, and for sharing it freely. I’ll let you know once my modifications are done.
@fabregus,
Here’s a hint for you:
function get_thanks (){
global $wpdb,$post;
$table = $wpdb->prefix.$this->table;
$thanks = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $table WHERE post_id='$post->ID' "));
return $thanks;
}
You can actually make the same mySQL inquiry anywhere inside wordpress as long as you call global $wpdb. The most important line in that code above is this:
SELECT COUNT(*) FROM $table WHERE post_id='$post->ID'
That’s a mySQL query that will count all entries that have your current post’s ID attached to it. $table should be wp_thank if you have not changed prefix when you set up wordpress. Hope this helps you out.