Polls

  • JNext lesson
  • KPrevious lesson
  • FSearch lessons
  • EscClear search

Most WordPress polls plugins are a separate install with their own bloat. Core Forms includes polls as a built-in feature: simple voting polls with their own post type, dedicated database tables for votes, and frontend rendering that doesn’t drag a charting library onto every page.

Creating a Poll

  1. Go to Core Forms > Polls in the WordPress admin.
  2. Click Add New.
  3. Enter a poll title and question.
  4. Add poll options (each option is a possible answer).
  5. Configure poll settings.
  6. Publish the poll.

Poll Settings

Allow Multiple Selections

When enabled, voters can select more than one option. When disabled, only a single choice is allowed.

Setting: allow_multiple

Show Results Before Voting

When enabled, voters can see the current results before casting their vote. When disabled, results are only shown after voting.

Setting: show_results_before_vote

Vote Limit Method

Controls how duplicate votes are prevented:

  • IP – One vote per IP address.
  • User – One vote per logged-in user (requires login).
  • Cookie – One vote per browser (uses a cookie to track).

Setting: vote_limit

End Date

Optional date and time when the poll closes. After this date, no new votes are accepted and results are shown.

Setting: ends_at

Displaying a Poll

Shortcode

[cf_poll id="1"]
[cf_poll slug="favorite-color"]

PHP

$poll = cf_get_poll_by_slug( 'favorite-color' );
// Use poll data in your template

How Voting Works

  1. The poll is rendered on the frontend with options displayed as radio buttons (single choice) or checkboxes (multiple choice).
  2. When a user votes, the vote is submitted via AJAX.
  3. The vote is recorded in the wp_cf_poll_votes table.
  4. The updated results are returned and displayed.
  5. Subsequent visits show the results instead of the voting form (based on the vote limit method).

Poll Data

Polls are stored in two places:

  • The core-poll custom post type holds the poll title and slug.
  • The wp_cf_polls table stores the question, options, settings, status, and timestamps.
  • The wp_cf_poll_votes table stores individual votes with the poll ID, selected option index, IP address, user ID, and timestamp.

Programmatic Access

Get a poll

$poll = cf_get_poll( $poll_id );
$poll = cf_get_poll_by_post_id( $post_id );
$poll = cf_get_poll_by_slug( 'my-poll' );

Get poll results

// Returns array of option_index => vote_count
$results = cf_get_poll_results( $poll_id );

// Returns total number of votes
$total = cf_get_poll_total_votes( $poll_id );

Poll Properties

The Poll object has these properties:

  • id – Poll ID
  • post_id – Associated post ID
  • question – The poll question
  • options – Array of option strings
  • settings – Poll settings array
  • status – “active” or “closed”
  • ends_at – End date (null if no end date)
  • created_at – Creation timestamp

Poll Methods

  • is_active() – Returns true if the poll is active and not past its end date.
  • allows_multiple() – Returns true if multiple selections are allowed.
  • shows_results_before_vote() – Returns true if results are visible before voting.
  • get_vote_limit_method() – Returns the vote deduplication method (“ip”, “user”, or “cookie”).

Frontend Assets

Polls load their own CSS (poll-frontend.css) and JavaScript (poll-frontend.js) for rendering and vote handling. These are only loaded on pages where a poll is displayed.

Polls store votes in dedicated tables documented in the database schema lesson. For gathering more than a single vote, build a real form with custom HTML instead.