public function get_post_nomination_status($date, $item_id, $post_type, $updateCount = true) { //Get the query object, limiting by date, type and metavalue ID. $postsAfter = pf_get_posts_by_id_for_check($date, $post_type, $item_id); //Assume that it will not find anything. $check = false; if ($postsAfter) { global $post; foreach ($postsAfter as $post) { setup_postdata($post); $id = get_the_ID(); $origin_item_id = get_post_meta($id, 'origin_item_ID', true); if ($origin_item_id == $item_id) { $check = true; //Only update the nomination count on request. if ($updateCount) { $nomCount = get_post_meta($id, 'nomination_count', true); $nomCount++; update_post_meta($id, 'nomination_count', $nomCount); $current_user = wp_get_current_user(); if (0 == $current_user->ID) { //Not logged in. //If we ever reveal this to non users and want to count nominations by all, here is where it will go. } else { $nominators = get_post_meta($id, 'nominator_array', true); $nominators[] = $current_user->ID; update_post_meta($id, 'nominator_array', $nominators); } return $check; break; } } } } return $check; }
public function get_post_nomination_status($date, $item_id, $post_type, $updateCount = true) { global $post; //Get the query object, limiting by date, type and metavalue ID. pf_log('Get posts matching ' . $item_id); $postsAfter = pf_get_posts_by_id_for_check($post_type, $item_id); //Assume that it will not find anything. $check = false; pf_log('Check for nominated posts.'); if ($postsAfter->have_posts()) { while ($postsAfter->have_posts()) { $postsAfter->the_post(); $id = get_the_ID(); pf_log('Deal with nominated post ' . $id); $origin_item_id = pf_retrieve_meta($id, 'origin_item_ID'); $current_user = wp_get_current_user(); if ($origin_item_id == $item_id) { $check = true; //Only update the nomination count on request. if ($updateCount) { if (0 == $current_user->ID) { //Not logged in. //If we ever reveal this to non users and want to count nominations by all, here is where it will go. pf_log('Can not find user for updating nomionation count.'); $nomCount = pf_retrieve_meta($id, 'nomination_count'); $nomCount++; pf_update_meta($id, 'nomination_count', $nomCount); $check = 'no_user'; } else { $nominators_orig = pf_retrieve_meta($id, 'nominator_array'); if (!in_array($current_user->ID, $nominators_orig)) { $nominators = $nominators_orig; $nominator = $current_user->ID; $nominators[] = $current_user->ID; pf_update_meta($id, 'nominator_array', $nominator); $nomCount = pf_get_post_meta($id, 'nomination_count', true); pf_log('So far we have a nominating count of ' . $nomCount); $nomCount++; pf_log('Now we have a nominating count of ' . $nomCount); $check_meta = pf_update_meta($id, 'nomination_count', $nomCount); pf_log('Attempt to update the meta for nomination_count resulted in: '); pf_log($check_meta); $check = true; } else { $check = 'user_nominated_already'; } } return $check; break; } } else { pf_log('No nominations found for ' . $item_id); $check = 'unmatched_post'; } } } else { pf_log(' No nominations found for ' . $item_id); $check = 'unmatched_post'; } wp_reset_postdata(); return $check; }