WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to get the key values for multiple posts with get_post_meta but am having no luck so far. In short, I have a function that adds 'votes' and 'thevoters' to each post. I want to check to make sure if someone's UserID is in any one of the 'thevoters' fields (spanning across multiple posts) they will not be able to vote again.

The following query gets the value of a specific post. I need to get the values across all posts with that key.

$voters = get_post_meta($id, 'thevoters', true);

My SQL query is:

SELECT * FROM `carcrazy_postmeta` WHERE meta_key='thevoters'

I am using this voting code as a reference - http://bavotasan.com/tutorials/simple-voting-for-wordpress-with-php-and-jquery/

Any ideas?

share|improve this question
See the answer i gave to Getting all values for a custom field key – t31os Mar 1 '11 at 16:07
up vote 0 down vote accepted

why not add a filed to user meta once they have voted and just check to see if that specific user can vote?

add to your add vote function this lines:

global $current_user;
add_user_meta( $current_user->ID , 'voted', true );

now if a user votes it saves a usermeta filed.

then you can create a simple function to check if a user can vote again:

function has_he_voted($user_id){
    $v = get_user_meta( $user_id , 'voted', true );
    if ($v = true){
        return true;
        return false;

and to use it and check if the user has voted you just call that function passing a user_id:

if (has_he_voted(12)){
   //can't vote again ,you can only vote once 
   //user has already voted
   //you can vote
   //user has never voted before
share|improve this answer

Your Answer


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.