0

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!

1 Answer 1

1

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 );
}     
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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