gform_after_submission content appears immediately after , not in post body [closed]

Just thinking on a Friday night (so untested), but:

You are outputing the result directly to the page. Of course it is going to display straight after the body tag. What you need to do is store that HTML snippet, and append/insert into the content using the_content filter as s_ha_dum suggested.

This is untested, and typed after a few Pernods, but:

class wpse_95891 {

    protected $post_content;

    public function __construct() {
        add_action("gform_after_submission_18", array($this, "set_post_content"), 10, 2);
        add_filter("the_content", array($this, "the_content"));
    }

    /**
    * @param array $entry the Gravity Forms entry/lead "object"
    * @param array $form the Gravity Forms form "object"
    */
    public function set_post_content($entry, $form) {
        // insert all of your query logic here...

        // grab the output and store in a field for later
        ob_start();
        ?>
        <ul><?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
        <li><?php the_title(); ?></li>
        <?php endwhile; ?>
        </ul>
        <?php
        $this->post_content = ob_get_clean();
    }

    /**
    * @param string $the_content post/page content
    * @return string
    */
    public function the_content($content) {
        if (!empty($this->post_content)) {
            $content .= post_content;
        }

        return $content;
    }
}

new wpse_95891();

Leave a Comment