admin管理员组文章数量:1312751
I have a page with a shortcode that displays a dropdown. I just can't figure out how to return that value to a function/page to show the resulting information. The second page would take that value and show a list. I've tried everything I can think of. Any suggestion will be appreciated. Sample code would be wonderful. Thank you,
I have a page with a shortcode that displays a dropdown. I just can't figure out how to return that value to a function/page to show the resulting information. The second page would take that value and show a list. I've tried everything I can think of. Any suggestion will be appreciated. Sample code would be wonderful. Thank you,
Share Improve this question asked Dec 31, 2020 at 0:52 BudBud 438 bronze badges 1- Thank you. That was so helpful. – Bud Commented Dec 31, 2020 at 18:51
1 Answer
Reset to default 0There are plenty of ways this can be done. Here is one rudimentary version of doing this using the GET
method and two different shortcodes for the two pages. You have to place the code in your theme's functions.php
and to create two different pages and place [first-page]
shortcode on the first page, and [second-page]
shortcode on the second page and use the form on the first page.
<?php
/**
* Shortcode for the First page.
*
* Show form on the first page to grab information.
*/
function wpse380676_first_page_shortcode() {
$second_page_id = 1832;
ob_start();
?>
<form action="<?php echo get_the_permalink($second_page_id) ?>" method="GET">
<label><input type="radio" name="question" value="yes"> Yes</label>
<label><input type="radio" name="question" value="no"> No</label>
<button type="submit">Submit</button>
</form>
<?php
echo ob_get_clean();
}
add_shortcode( 'first-page', 'wpse380676_first_page_shortcode' );
/**
* Shortcode for the Second page.
*
* Handle data from the previous page and do something.
*/
function wpse380676_second_page_shortcode() {
$question = filter_input(INPUT_GET, 'question', FILTER_SANITIZE_STRING);
if (!$question) {
return;
}
if ('yes' === $question) {
echo 'The answer is Yes';
} else {
echo 'The answer is No';
}
}
add_shortcode( 'second-page', 'wpse380676_second_page_shortcode' );
Tested in WordPress 5.6 with the default theme 'Twenty Twenty One'
本文标签: From a shortcode I want to pass a value to display a different page
版权声明:本文标题:From a shortcode I want to pass a value to display a different page 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741877589a2402556.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论