I have the following function that successfully uses form fields (IDs 13 and 18) from a Gravity Form (ID 18) as parameters within wp_query.
This displays a list of posts with specific taxonomy terms that match those chosen in the form:
add_action("gform_after_submission_18", "set_post_content", 10, 2);
function set_post_content($entry, $form){
//getting post
$post = get_post($entry["post_id"]);
$concern = $entry[13];
$sensitivity = $entry[18];
$loop = new WP_Query( array(
'post_type' => 'recommended',
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'concern',
'field' => 'slug',
'terms' => $concern
),
array(
'taxonomy' => 'sensitivity',
'field' => 'slug',
'terms' => $sensitivity
)
),
'orderby' => 'title',
'posts_per_page' => '-1',
'order' => 'ASC'
)
); ?>
//THIS BIT DISPLAYS THE CORRECT LOOP BUT IT APPEARS IMMEDIATELY AFTER <BODY> RATHER THAN IN THE POST CONTENT
<ul><?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<li><?php the_title(); ?></li>
<?php endwhile; ?></ul>
<?php
//THIS BIT DISPLAYS THE CHOSEN FORM FIELD INSIDE MY POST CONTENT - WRONG CONTENT, RTIGHT POSITION
$post->post_content =
"<ul>" .
$concern .
"<br/> sensitivity: " .
$sensitivity .
" </ul>"
;
}
The problem is that this is being inserted immediately after the ‘body’ tag rather than into the post body.
How do I move this to where it should be?!
I could well be going about this all wrong and I’m stumped
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:
thanks for all your input..
I just managed to achieve what I needed (with massive thanks to Alex at WPMU!), using global declarations –
Probably not the most elegant solution but it does what I need. This is actually a much simplified version of what I’m doing and this way I know how to make it work!
Please do point out any issues with what I’ve done if there are any!?