WPIntell

Source evidence

Use TotalContest variable in PHP

TotalPoll for Polls and Contests · support · 2024-08-28T11:03:00+00:00

mixedsentiment
mediumseverity
0.84relevance
9replies
Evidence linked to opportunitycommercial context

Proof Health

Open evidence

Commercial opportunities need traceable source links before they are treated as build-worthy.

4 / 29 rows with source links

13.8% of this page's analysis has direct source links.

0 build-decision rows missing links

0 rows here require auditable proof before promotion.

25 rows with no attached evidence

0 rows have source counts but still need direct links.

Conversation

support
cyberlp23 resolved
Hello, I’ve bought the Pro version of TotalContest. I’m trying to retrieve the average rate variable for each submission in a contest in order to display something in PHP in my WordPress page. How would I be able to do that? Thanks! And another PHP question: is there a way to input PHP variables into the TotalContest fields? I’ve tried with Custom block but it does not seem to work. Hi @cyberlp23 You can use the metadata attached to the submission: get_post_meta(SUBMISSION_ID, '_tc_rate', true); As for the second question, could you please elaborate on the use case? I hope this answers your questions! If you need any more clarification, please don’t hesitate to let us know. Regards, Thank you for your answer, I will try the get_post_meta. Also, the idea with retrieving the average_rate is to display a leaderboard. It says in your faq that it is possible to do it, but how ? 🙂 As for the second question: – I have a PHP variable $team_id which is defined in my custom WP template where I use TotalSuite (it’s stored in a PHP session + cookie when user logs in). For example, $team_id = 37. – Is there a way to display that value on their submissions? This reply was modified 1 year, 9 months ago by cyberlp23 . The first question is solved, but not the second. Any way of using PHP variables in the TotalContest custom fields? Hi, You can use JS to populate the value after adding the team_id field to the participation form (via the contest editor). Afterwards, you can use that field in the submission view blocks to display its value. Sample: add_action( 'wp_enqueue_scripts', function () { $teamId = 0; // Retrieve it from session or other source wp_add_inline_script( 'totalcontest-frontend', sprint('document.querySelector("#team-id-field").value = "%s"', $teamId); ); } ); I hope it helps! If you need any more help, please don’t hesitate to let me know. Regards, Thanks. I tweaked your script a little bit to make it work. add_action( 'wp_enqueue_scripts', function () { $handle = 'totalcontest-frontend'; $script_url = plugins_url( 'totalcontest/assets/dist/scripts/frontend.js', __FILE__ ); wp_enqueue_script( $handle, $script_url, array(), null, true ); if(isset($_SESSION['team_id'])) { $teamId = $_SESSION['team_id']; } else { $teamId = 0; } $inline_script = sprintf( 'document.addEventListener("DOMContentLoaded", function() { var teamIdField = document.querySelector("#id_equipe-field"); if (teamIdField) { teamIdField.value = "%d"; } });', $teamId, $teamId ); wp_add_inline_script( $handle, $inline_script ); }, 20 ); Now, is there a way to display this as a pre-filled, non-modifiable input field in the Participate page? (that I still will be able to display on the Submission page) This reply was modified 1 year, 8 months ago by cyberlp23 . I found the way ^^ add_action( 'wp_enqueue_scripts', function () { $handle = 'totalcontest-frontend'; $script_url = plugins_url( 'totalcontest/assets/dist/scripts/frontend.js', __FILE__ ); wp_enqueue_script( $handle, $script_url, array(), null, true ); $teamId = isset($_SESSION['team_id']) ? $_SESSION['team_id'] : 0; $inline_script = sprintf( 'document.addEventListener("DOMContentLoaded", function() { var teamIdField = document.querySelector("#id_equipe-field"); if (teamIdField) { teamIdField.value = "%d"; teamIdField.setAttribute("readonly", "readonly"); } });', $teamId ); wp_add_inline_script( $handle, $inline_script ); }, 20 ); Hi @cyberlp23 That’s great! Thanks for sharing the snippet. Regards, I’ve bought the Pro version of TotalContest. Closing this topic as @totalsuite knows they must not support customers on this site. This site is only for users of the opensource plugin and not someone who paid the developer. For pro or commercial product support please contact the developer directly on their site. This includes any pre-sales topics as well. As the developer is aware, commercial products are not supported in these forums . I am sure they will have no problem supporting you there.

Comments

9 shown
cyberlp23 2024-08-28T16:39:00+00:00

And another PHP question: is there a way to input PHP variables into the TotalContest fields? I’ve tried with Custom block but it does not seem to work.

TotalSuite 2024-08-30T07:18:00+00:00

Hi @cyberlp23 You can use the metadata attached to the submission: get_post_meta(SUBMISSION_ID, '_tc_rate', true); As for the second question, could you please elaborate on the use case? I hope this answers your questions! If you need any more clarification, please don’t hesitate to let us know. Regards,

cyberlp23 2024-08-30T13:34:00+00:00

Thank you for your answer, I will try the get_post_meta. Also, the idea with retrieving the average_rate is to display a leaderboard. It says in your faq that it is possible to do it, but how ? 🙂 As for the second question: – I have a PHP variable $team_id which is defined in my custom WP template where I use TotalSuite (it’s stored in a PHP session + cookie when user logs in). For example, $team_id = 37. – Is there a way to display that value on their submissions? This reply was modified 1 year, 9 months ago by cyberlp23 .

cyberlp23 2024-09-09T06:49:00+00:00

The first question is solved, but not the second. Any way of using PHP variables in the TotalContest custom fields?

TotalSuite 2024-09-09T08:42:00+00:00

Hi, You can use JS to populate the value after adding the team_id field to the participation form (via the contest editor). Afterwards, you can use that field in the submission view blocks to display its value. Sample: add_action( 'wp_enqueue_scripts', function () { $teamId = 0; // Retrieve it from session or other source wp_add_inline_script( 'totalcontest-frontend', sprint('document.querySelector("#team-id-field").value = "%s"', $teamId); ); } ); I hope it helps! If you need any more help, please don’t hesitate to let me know. Regards,

cyberlp23 2024-09-09T11:47:00+00:00

Thanks. I tweaked your script a little bit to make it work. add_action( 'wp_enqueue_scripts', function () { $handle = 'totalcontest-frontend'; $script_url = plugins_url( 'totalcontest/assets/dist/scripts/frontend.js', __FILE__ ); wp_enqueue_script( $handle, $script_url, array(), null, true ); if(isset($_SESSION['team_id'])) { $teamId = $_SESSION['team_id']; } else { $teamId = 0; } $inline_script = sprintf( 'document.addEventListener("DOMContentLoaded", function() { var teamIdField = document.querySelector("#id_equipe-field"); if (teamIdField) { teamIdField.value = "%d"; } });', $teamId, $teamId ); wp_add_inline_script( $handle, $inline_script ); }, 20 ); Now, is there a way to display this as a pre-filled, non-modifiable input field in the Participate page? (that I still will be able to display on the Submission page) This reply was modified 1 year, 8 months ago by cyberlp23 .

cyberlp23 2024-09-09T15:59:00+00:00

I found the way ^^ add_action( 'wp_enqueue_scripts', function () { $handle = 'totalcontest-frontend'; $script_url = plugins_url( 'totalcontest/assets/dist/scripts/frontend.js', __FILE__ ); wp_enqueue_script( $handle, $script_url, array(), null, true ); $teamId = isset($_SESSION['team_id']) ? $_SESSION['team_id'] : 0; $inline_script = sprintf( 'document.addEventListener("DOMContentLoaded", function() { var teamIdField = document.querySelector("#id_equipe-field"); if (teamIdField) { teamIdField.value = "%d"; teamIdField.setAttribute("readonly", "readonly"); } });', $teamId ); wp_add_inline_script( $handle, $inline_script ); }, 20 );

TotalSuite 2024-09-10T09:02:00+00:00

Hi @cyberlp23 That’s great! Thanks for sharing the snippet. Regards,

Jan Dembowski 2025-01-02T21:02:00+00:00

I’ve bought the Pro version of TotalContest. Closing this topic as @totalsuite knows they must not support customers on this site. This site is only for users of the opensource plugin and not someone who paid the developer. For pro or commercial product support please contact the developer directly on their site. This includes any pre-sales topics as well. As the developer is aware, commercial products are not supported in these forums . I am sure they will have no problem supporting you there.