• Resolved Sameer

    (@msameerbutt)


    Is there a way for users on the archive page to vote on polls they haven’t previously voted on instead of just seeing all results? If not, can you recommend either a way to go about getting that functionality or a link to someone who’s already customized the plugin to do that? Thanks!

    https://www.ads-software.com/plugins/wp-polls/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Lester Chan

    (@gamerz)

    Nope, the archive page is just for display the results of the poll. The reason you can’t vote is because it will generate a lot of queries on that page if I allow people to vote.

    I don’t think there is anyone who did that yet because it requires quite a bit of coding.

    Thread Starter Sameer

    (@msameerbutt)

    Thanks for you quick reply
    I have done this functionality by adding a function to my functions.php.

    I know it may not be robust solution but it can save someone time, below is the function code

    public youfunction ($args=array()){
    
          // display polls forcefully as poll archive page not allow voting
          global $wpdb;
          $output = "";
          extract($args,EXTR_OVERWRITE);
          $offset = isset($offset) && is_numeric($offset) ? $offset : 0;
          if (function_exists('vote_poll') && !in_pollarchive()):;
            $polls_perpage = intval(get_option('poll_archive_perpage'));
            $polls_type = intval(get_option('poll_archive_displaypoll'));
            $polls_type_sql = '';
            // Determine What Type Of Polls To Show
            switch($polls_type) {
              case 1:
                $polls_type_sql = 'AND pollq_active = 0';
                break;
              case 2:
                $polls_type_sql = 'AND pollq_active = 1';
                break;
              case 3:
                $polls_type_sql = 'AND pollq_active IN (0,1)';
                break;
            }
            $post__not_in = isset($post__not_in) && !empty($post__not_in) ? 'AND pollq_id NOT IN('.$post__not_in.')' : '';
            $total_polls = $wpdb->get_var("SELECT COUNT(pollq_id) FROM $wpdb->pollsq WHERE 1 $polls_type_sql AND pollq_active != -1");
            $questions = $wpdb->get_results("SELECT pollq_id FROM $wpdb->pollsq WHERE 1 $polls_type_sql $post__not_in ORDER BY pollq_id DESC LIMIT $offset, $polls_perpage");
            if($questions) {
              foreach($questions as $question) {
                ob_start();
                get_poll($question->pollq_id);
                $output .= ob_get_contents();
                ob_end_clean();
              }
              if($total_polls > $polls_perpage):
                // ajax load more button
              endif;
            }else{
              // NO POLL FOUND
            }
          endif;
          return $output;
      }

    You can adjust this function according to your own requirement
    of-course i have extract this code from plugin and re arrange it.

    Thanks.

    Hi msameerbutt,

    Any chance you can reply with a short & simple guide (for a php newbie like me) on how to get this functionality? Where EXACTLY do I put the code? What’s the file name? (functions.php? which one?, line etc.

    Please, please, please. I’ve been trying to do this for ages.

    Thanks in adavance!

    Thread Starter Sameer

    (@msameerbutt)

    Sorry for late reply, this not simple but you can give it a try

    1) copy this function to your function.php
    2) paste this code <?php echo(youfunction ());?> where you want to display the polls

    Thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Plugin: WP-Polls] Voting on the archive page’ is closed to new replies.