Title: Multiple polls as a shortcode
Last modified: July 29, 2020

---

# Multiple polls as a shortcode

 *  Resolved [Kliment Malenko](https://wordpress.org/support/users/malenko123/)
 * (@malenko123)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/multiple-polls-as-a-shortcode/)
 * Hi,
 * Just testing your plugin – but I cannot seem to find any way to display mutiple
   polls on one page using a shortcode?
 * Currently I’m using [onyx-poll]
 * Can you please let me know how can I display multiple polls ( I need it strictly
   as a shortcode ). Thank you 🙂

Viewing 6 replies - 1 through 6 (of 6 total)

 *  Plugin Author [andremacola](https://wordpress.org/support/users/andremacola/)
 * (@andremacola)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/multiple-polls-as-a-shortcode/#post-13188137)
 * If you are using the Gutenberg editor you can use the ACF Onyx Poll Block under
   the blocks options.
 * For shortcode, each poll has a unique ID and you can pass with the ID parameter.
   For example: `[onyx-poll id=XX]`
 * So for multiple polls, just add multiple shortcodes like:
 * `[onyx-poll id=10]`
    `[onyx-poll id=11]` `[onyx-poll id=12]`
 * More information at **FAQ** area on plugin page.
    -  This reply was modified 5 years, 10 months ago by [andremacola](https://wordpress.org/support/users/andremacola/).
 *  Thread Starter [Kliment Malenko](https://wordpress.org/support/users/malenko123/)
 * (@malenko123)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/multiple-polls-as-a-shortcode/#post-13188233)
 * Alright, thank you. That’ll do for now 🙂
 * Anyway – one more question, is there any reason I cannot get the current user
   data inside your plugin?
 * Is there any easy way to do this?
 * Almost every time I get 0 for current ID.
 * I’m trying to get the current user ID inside poll-api.php right before you post
   the results in the poll post.
 *  Plugin Author [andremacola](https://wordpress.org/support/users/andremacola/)
 * (@andremacola)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/multiple-polls-as-a-shortcode/#post-13188252)
 * I would need to see how you are doing this. Maybe it’s something related to WordPress
   REST API
 * If you create an issue on Github with some example, I can check in my spare time
 *  Thread Starter [Kliment Malenko](https://wordpress.org/support/users/malenko123/)
 * (@malenko123)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/multiple-polls-as-a-shortcode/#post-13189083)
 * Hey,
 * Actually haven’t inserted any big code – just tried getting the current user 
   in function ‘vote’.
 *     ```
       /**
       	 * Compute vote
       	 * @param int $req['poll'] poll ID required
       	 * @param int $req['choice'] poll answer choice required
       	 * @todo: [$poll_choice - 1] is just a temp fix. maybe acf/settings/row_index_offset filter?
       	 */
       	public function vote($req) {
   
       		// params vars
       		$poll_id       = $req['poll'];
       		$poll_choice   = (int) $req['choice'];
       		$poll_answers  = get_field($this->field['answers'], $poll_id);
       		$poll_total    = get_field($this->field['total'], $poll_id);
       		$poll_expired  = get_field($this->field['expired'], $poll_id);
       		$poll_limit    = get_field($this->field['limit_vote'], $poll_id);
   
       		// validate params from req
       		if (!is_numeric($poll_id) || !isset($poll_choice) || empty($poll_answers[$poll_choice - 1])) {
       			return new WP_Error('error', $this->message['invalid'], array('status' => 400));
       		}
       		if ($poll_expired || get_post_type($poll_id) != 'onyxpolls') {
       			return new WP_Error('error', $this->message['no_exist'], array('status' => 400));
       		}
       		if (isset($_COOKIE["onyx_poll_limit_$poll_id"]) && $poll_limit != 1) {
       			$response = array(
       				"code"     => "not_allowed",
       				"id"       => $poll_id,
       				"message"  => $this->message['no_allowed'],
       				"voted"    => false,
       				"data"     => ["status" => 200]
       			);
       		} else {
       			// update vote fields
       			$add_vote = array(
       				"votes" => $poll_answers[$poll_choice - 1]['votes']+1
       			);
       			$row   = update_row($this->field['answers'], $poll_choice, $add_vote, $poll_id);
       			$total = update_field($this->field['total'], $poll_total+1, $poll_id);
   
       			// set cookies
       			// limit = 1 (free vote)
       			// limit = 2 (per device/no expires)
       			$this->setcookie($poll_id, $poll_choice);
   
   
       	   		$user_id = get_current_user_id(); // RETURNS 0
   
       			// global $current_user;
       		 	//get_currentuserinfo();
       		   	//var_dump($current_user->ID);
   
       	   		/* when the POLL is answered get the current user ID in an repeater acf field which I've implemented in each post (poll) via acf */
       	   		/* I'm trying to LIMIT the submission to a USER - so not per defice - but poll per user */	   		
       			$field_key = "field_5f220c11c3fc1"; // repeater field
       			$value = array('field_5f220c36c3fc2' => $user_id);
       			add_row($field_key, $value, $poll_id);
   
       			// do_action('acf/save_post', $poll_id);		  
       			// wp_redirect(add_query_arg('updated', 'success', wp_get_referer()));
   
       			// return reponse
       			$response = array(
       				"code"     => ($row && $total) ? "success" : 'error',
       				"poll"     => $poll_id,
       				"choice"   => $poll_choice,
       				"message"  => ($row && $total) ? $this->message['success'] : $this->message['error'],
       				"voted"    => ($row && $total) ? true : false,
       				"data"     => ["status" => 200]
       			);
       		}
   
       		$response += $this->poll_data($poll_id);
       		return new WP_REST_Response($response, 200);
       	}
       ```
   
 * Take a look at the comments. Tried to take the current user id with get_current_user_id()
   and it returns 0.
 * What I’m actually trying to do is to limit the poll per USER.
 * Thank you.
 *  Plugin Author [andremacola](https://wordpress.org/support/users/andremacola/)
 * (@andremacola)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/multiple-polls-as-a-shortcode/#post-13189324)
 * The WordPress REST API operates differently for user roles
 * Please, see: [https://stackoverflow.com/questions/55801175/get-current-user-inside-register-rest-route-method](https://stackoverflow.com/questions/55801175/get-current-user-inside-register-rest-route-method)
 *  Thread Starter [Kliment Malenko](https://wordpress.org/support/users/malenko123/)
 * (@malenko123)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/multiple-polls-as-a-shortcode/#post-13190094)
 * Alright, thanks – I’ll give it a look.
 * Anyhow any advice on how can I limit the poll to a user?

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Multiple polls as a shortcode’ is closed to new replies.

 * ![](https://ps.w.org/acf-onyx-poll/assets/icon-256x256.png?rev=2312534)
 * [ACF Onyx Poll](https://wordpress.org/plugins/acf-onyx-poll/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/acf-onyx-poll/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/acf-onyx-poll/)
 * [Active Topics](https://wordpress.org/support/plugin/acf-onyx-poll/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/acf-onyx-poll/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/acf-onyx-poll/reviews/)

## Tags

 * [multiple](https://wordpress.org/support/topic-tag/multiple/)
 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)

 * 6 replies
 * 2 participants
 * Last reply from: [Kliment Malenko](https://wordpress.org/support/users/malenko123/)
 * Last activity: [5 years, 10 months ago](https://wordpress.org/support/topic/multiple-polls-as-a-shortcode/#post-13190094)
 * Status: resolved