Comments (1)
After some research, I believe there is no relation between a poll and a post. So I don't think this is possible. Please correct me if I'm wrong.
So, I created a script which will check if there is a poll id attached to the post. If not, it will check if there is a poll with the same title. If not, it will create a poll and attach it to the post meta. Please see this template script, maybe it could help someone:
function get_or_create_wp_poll_id_for_post($postId)
{
$pollId = a_function_to_get_post_meta('poll_id', $postId);
if (empty($pollId)) {
global $wpdb;
$title = get_the_title($postId);
$pollTitle = What rating would you give ' . $title . '?';
$pollId = $wpdb->get_var("SELECT pollq_id FROM " . $wpdb->pollsq . " WHERE pollq_question = '" . $pollTitle . "' LIMIT 1");
if (!$pollId) {
$newQuestion = $wpdb->insert(
$wpdb->pollsq,
[
'pollq_question' => $pollTitle,
'pollq_timestamp' => current_time('timestamp'),
'pollq_totalvotes' => 0,
'pollq_active' => 1,
'pollq_expiry' => 0,
'pollq_multiple' => 0,
'pollq_totalvoters' => 0
],
[
'%s',
'%s',
'%d',
'%d',
'%d',
'%d',
'%d'
]
);
if ($newQuestion) {
$pollId = (int)$wpdb->insert_id;
a_function_to_set_post_meta($id, 'poll_id', $pollId);
$answers = ['Not interesting', 'Interesting', 'Very interesting'];
foreach ($answers as $answer) {
$wpdb->insert(
$wpdb->pollsa,
[
'polla_qid' => $pollId,
'polla_answers' => $answer,
'polla_votes' => 0
],
[
'%d',
'%s',
'%d'
]
);
}
}
}
}
return $pollId;
}
from wp-polls.
Related Issues (20)
- Remove CSS
- Deregister plugin CSS HOT 1
- Cant create poll
- Multi vote problem HOT 1
- Button color and text not visable HOT 1
- Can't access to "Manage polls" HOT 1
- Ajax on password secured wp-admin folder HOT 2
- Add hooks for all templates rather than just voting form header, body & footer HOT 3
- All poll options returning to "No Poll Option Updated"
- 100% result for last option of new poll in Archive polls
- polls_archive() isn't running the template filters HOT 1
- Poll not appearing on mobile version of site
- PollsWidget not working in new Block-Widget-Area
- [Question] Token based poll concept?
- Admin are shows poll link but 404's
- Feature request: Add box to input name and email when submitting
- Feature Request: GamiPress integration
- Include a shortcode or/and function to get the latest poll
- Feature proposal - Use of post type Objects as answers HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wp-polls.