Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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);
    }
    ?>
share|improve this question
    
The two images you mentioned seem to be identical. Not sure if you're still trying to solve this one. Let me know. –  GhostToast Jun 21 '13 at 13:47
    
Yes, they are very similar, and in fact I want to use the knowledge from one of those questions to solve another. Difference is that here I create and publish 1 post_type and update another CPT which already exists and at that page should be only added info about the submitter(name)+ possibly (age) OR from which country is so(country), I don't care where in the page, this way I would love to see the popularity of every page by seeing submitters in some "div".Second post is different, as the previuos case it will creates new custom_post_type but will also generate a brand new custom_post_type. –  Daniel Foltynek Jun 21 '13 at 14:07
1  
No I'm talking about the images linked are identical. –  GhostToast Jun 21 '13 at 14:07
    
ahh I see now, you are right! I have changed that now. –  Daniel Foltynek Jun 21 '13 at 14:20
add comment

1 Answer

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>';
}
share|improve this answer
    
But the ID of the page will be unknown, because the little form is right now on the bottom of every post page, I have 1700 clubs there and on every post page will girls ask for the job, take a look here, it is in italian: 4ella.com/2012/12/la-perla-nightclub-cagliari , the ID of the page has to be get dynamically. –  Daniel Foltynek Jun 21 '13 at 14:56
    
In that case, you will need to decide where you want to save it. It's a little unorthodox, but you could save it as post_meta for an important page, and just always reference it that way. For example, the home page. And instead of using $post->ID to get it, use that page's unique ID. –  GhostToast Jun 21 '13 at 15:02
    
I would better choose your recommended solution, I don't know what should be the best one, but I hope that in future on that site should have 1000's posts their list of submitters (with their links to their portfolios), so it should be a lot of new data. –  Daniel Foltynek Jun 21 '13 at 15:12
    
Should be fine to use home page's ID as long as you never delete the home page. Otherwise you could store this stuff in a custom table, but that is a topic for another question I think. –  GhostToast Jun 21 '13 at 15:16
    
I will be very very happy if this feature will work and sincerely if this feature doesn't worse my website performance I don't mind where to store it, I think that storing I can always change in the future when I will have more time and more ability to do those things by myself, but as I said, you are an expert here, so if you will choose more easy way, I would be happy anyway, because it will work –  Daniel Foltynek Jun 21 '13 at 15:25
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.