Title: Use TotalContest variable in PHP
Last modified: January 2, 2025

---

# Use TotalContest variable in PHP

 *  Resolved [cyberlp23](https://wordpress.org/support/users/cyberlp23/)
 * (@cyberlp23)
 * [1 year, 9 months ago](https://wordpress.org/support/topic/use-totalcontest-variable-in-php/)
 * 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!

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

 *  Thread Starter [cyberlp23](https://wordpress.org/support/users/cyberlp23/)
 * (@cyberlp23)
 * [1 year, 9 months ago](https://wordpress.org/support/topic/use-totalcontest-variable-in-php/#post-17981191)
 * 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.
 *  Plugin Author [TotalSuite](https://wordpress.org/support/users/totalsuite/)
 * (@totalsuite)
 * [1 year, 9 months ago](https://wordpress.org/support/topic/use-totalcontest-variable-in-php/#post-17984588)
 * Hi [@cyberlp23](https://wordpress.org/support/users/cyberlp23/)
 * You can use the metadata attached to the submission:
 *     ```wp-block-code
       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,
 *  Thread Starter [cyberlp23](https://wordpress.org/support/users/cyberlp23/)
 * (@cyberlp23)
 * [1 year, 9 months ago](https://wordpress.org/support/topic/use-totalcontest-variable-in-php/#post-17985466)
 * 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](https://wordpress.org/support/users/cyberlp23/).
 *  Thread Starter [cyberlp23](https://wordpress.org/support/users/cyberlp23/)
 * (@cyberlp23)
 * [1 year, 9 months ago](https://wordpress.org/support/topic/use-totalcontest-variable-in-php/#post-18002662)
 * The first question is solved, but not the second.
 * Any way of using PHP variables in the TotalContest custom fields?
 *  Plugin Author [TotalSuite](https://wordpress.org/support/users/totalsuite/)
 * (@totalsuite)
 * [1 year, 9 months ago](https://wordpress.org/support/topic/use-totalcontest-variable-in-php/#post-18002920)
 * 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:
 *     ```wp-block-code
       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,
 *  Thread Starter [cyberlp23](https://wordpress.org/support/users/cyberlp23/)
 * (@cyberlp23)
 * [1 year, 9 months ago](https://wordpress.org/support/topic/use-totalcontest-variable-in-php/#post-18003383)
 * Thanks. I tweaked your script a little bit to make it work.
 *     ```wp-block-code
       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, 9 months ago by [cyberlp23](https://wordpress.org/support/users/cyberlp23/).
 *  Thread Starter [cyberlp23](https://wordpress.org/support/users/cyberlp23/)
 * (@cyberlp23)
 * [1 year, 9 months ago](https://wordpress.org/support/topic/use-totalcontest-variable-in-php/#post-18004024)
 * I found the way ^^
 *     ```wp-block-code
       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 );
       ```
   
 *  Plugin Author [TotalSuite](https://wordpress.org/support/users/totalsuite/)
 * (@totalsuite)
 * [1 year, 9 months ago](https://wordpress.org/support/topic/use-totalcontest-variable-in-php/#post-18005314)
 * Hi [@cyberlp23](https://wordpress.org/support/users/cyberlp23/)
 * That’s great! Thanks for sharing the snippet.
 * Regards,
 *  Moderator [Jan Dembowski](https://wordpress.org/support/users/jdembowski/)
 * (@jdembowski)
 * Forum Moderator and Brute Squad
 * [1 year, 5 months ago](https://wordpress.org/support/topic/use-totalcontest-variable-in-php/#post-18222816)
 * > I’ve bought the Pro version of TotalContest.
 * Closing this topic as [@totalsuite](https://wordpress.org/support/users/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](https://wordpress.org/support/guidelines/#do-not-post-about-commercial-products).
   I am sure they will have no problem supporting you there.

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

The topic ‘Use TotalContest variable in PHP’ is closed to new replies.

 * ![](https://ps.w.org/totalpoll-lite/assets/icon-256x256.png?rev=2929430)
 * [TotalPoll for Polls and Contests](https://wordpress.org/plugins/totalpoll-lite/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/totalpoll-lite/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/totalpoll-lite/)
 * [Active Topics](https://wordpress.org/support/plugin/totalpoll-lite/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/totalpoll-lite/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/totalpoll-lite/reviews/)

## Tags

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

 * 9 replies
 * 2 participants
 * Last reply from: [Jan Dembowski](https://wordpress.org/support/users/jdembowski/)
 * Last activity: [1 year, 5 months ago](https://wordpress.org/support/topic/use-totalcontest-variable-in-php/#post-18222816)
 * Status: resolved