感谢您的所有意见。。我只是设法实现了我所需要的(非常感谢WPMU的Alex!),使用全局声明-
可能不是最优雅的解决方案,但它满足了我的需要。这实际上是一个非常简化的版本,我正在做什么,这样我知道如何使它工作!
如果有任何问题,请指出我所做的任何问题!?
add_action("gform_after_submission_18", "recommendations", 10, 2);
function recommendations($entry, $form){
global $concern;
global $sensitivity;
$post = get_post($entry["post_id"]);
$concern = $entry[13];
$sensitivity = $entry[18];
add_filter("the_content", "recommended");
}
function recommended() {
global $concern;
global $sensitivity;
echo \'Here are your recommendations, based on your chosen options: <br>\';
echo \'Sensitivity: \';
echo $sensitivity;
echo \'<br>Concern: \';
echo $concern;
echo \'<br><br>\';
$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\'
) );
while ( $loop->have_posts() ) : $loop->the_post(); ?>
<div class="">
<?php the_title(); ?><br>
<?php if ( has_post_thumbnail() ) { the_post_thumbnail("thumb"); } ?>
</div>
<?php endwhile;
}