gform_after_submission add list of form titles after the post content [closed]

Can you help me with the code where all I only want is to add the list of all submitters who submitted GF form on every post page right after the post content?
Every post has its small CPT form on the bottom of the page and submitted forms goes to the custom post type portfolio page. I want to also display the list of clickable titles (the name of submitters with some fields already merged together by GF form) of the form with URL of that created page.

image 1 before submition:
enter image description here

The post after 5 succesfull submitions, it should also be after the post content /div

image 2 after:
enter image description here

The code I would like to use is here:

<?php
    add_action("gform_after_submission_7", "set_post_content", 10, 2);
    function set_post_content($entry, $form){

        //getting post
        $post = get_post($entry["post_id"]);

        //adding after the post content - how can I get something like this ?:

       ul 
         li  
             a submitted portfolio URL 
                   div class"some class" 
                   submitted form title 
                  /div 
                /a 
              /li 
            /ul 


        //updating post
        wp_update_post($post);
    }
    ?>

1 Answer
1

In order to do this on the page where the form is, it would work well to know the ID of that page. We’ll assume you have that and just want to embed this information into this page. So in your gform_after_submission hook, you’ll want something like this:

$id_of_page = 36; // change this

// false means we want all values as array, not single
$array_of_submitters = get_post_meta($id_of_page, 'my_custom_field', false); 

if(empty($array_of_submitters)){
    // has not yet been made, setup variable
    $array_of_submitters = array();
}

// add new value to array
$array_of_submitters[] = $entry[12]; // whatever field you need

// update!
update_post_meta($id_of_page, 'my_custom_field', $array_of_submitters);

Then in your page, you’ll want to just echo those out like this:

$array_of_submitters = get_post_meta($post->ID, 'my_custom_field', false);

// make sure it has values first so we don't look foolish
if(!empty($array_of_submitters)){
    echo '<h4>People who did something</h4>';
    echo '<ul>';
        // echo each value out as list
        foreach($array_of_submitters as $submitter){
            echo '<li>'.$submitter.'</li>'; 
        }
    echo '</ul>';
}

Leave a Comment