Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

In an author.php template, i count the author post in a custom post type with $wpdb->get_var,

$post_author = $curauth->ID; //author id
$count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_author = $post_author AND post_type IN ('ideas') and post_status = 'publish'" );

is it possible to count the author, total votes saved in post meta with key 'votes'?
the value for every post is a number updated each time a user votes a post

thanks!

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

This wouldn't be possible unless you keep a log of users that have voted the Idea. You will have to create another hidden post_meta array which will store a list of all the users who have voted the Idea. In that way you could count the number of votes an author has given. Or better yet you could create and update the user_meta 'ideas_voted' when a particular idea is voted by a user.

if ( idea is voted ) {
    $ideas_voted = ( get_user_meta( $curauth->ID, 'ideas_voted' ) ) ? get_user_meta( $curauth->ID, 'ideas_voted' ) + 1 : 1;
    update_user_meta( $curauth->ID, 'ideas_voted', $ideas_voted );
}     
share|improve this answer
    
thanks a lot @Joshua! –  Philip Dec 10 '11 at 12:22
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.