Display posts based on quiz result [RESOLVED]

Hi, I have created a quiz and i want to display posts based on the result, how can I get the value of the result so as to make a condition?

Thank you

Hi @and
To display posts based on the result of a quiz created using Gravity Forms, you can use the Gravity Forms API and a custom function to retrieve the quiz result and use it to query your posts. Here’s a general outline of the steps you can follow:

  1. Install and activate the Gravity Forms plugin on your WordPress site, if it is not already installed.

  2. Create your quiz using the Gravity Forms plugin. Make sure to set up the form fields and configure the form settings as needed.

  3. Create a custom function to retrieve the quiz result using the Gravity Forms API in your WordPress theme. You can use the GFAPI::get_entry() function to retrieve the quiz result for a specific form entry.

  4. Use the quiz result to query your posts and display them on the front-end of your site. You can use the WP_Query class to create a custom loop to display the posts.

Here’s an example of a custom function that retrieves the quiz result and displays posts based on the result:

function display_posts_based_on_quiz_result() {
  // Retrieve the quiz result for a specific form entry
  $form_id = 1; // Replace with your form ID
  $entry_id = 2; // Replace with your entry ID
  $entry = GFAPI::get_entry($entry_id);
  $quiz_result = $entry[1]; // Replace 1 with the field ID of your quiz result field
  // Query posts based on the quiz result
  $args = array(
    'post_type' => 'post',
    'meta_key' => 'quiz_result',
    'meta_value' => $quiz_result
  $query = new WP_Query($args);
  // Display the posts
  if ($query->have_posts()) {
    while ($query->have_posts()) {

You can then call this function wherever you want to display the posts based on the quiz result.

I hope this helps! Let me know if you have any questions or need further assistance.

1 Like

Hi @faisalahammad,
thanks a lot for the advice it is a great method but unfortunately the client has changed the specifications and I will have to assign each block of questions a score and based on the score of the block show some posts. So in my step form i will display a lot of posts for each result.

Just finished share the work (I don’t think it will be a clean job)

A thousand thanks

1 Like