难道我们不能像普通的php一样从wordpress中的post变量访问内容吗?


Can't we access content from post variable in wordpress as normal php

我想在wordpress中编写搜索,我所做的是为wordpress站点的一个选项卡创建模板页面,并添加以下表单。

<?php  get_header(); ?>
            <div id="primary" class="site-content">
                <div id="content" role="main">
                    <?php while ( have_posts() ) : the_post(); ?>
                        <?php //get_template_part( 'content', 'page' ); ?>
                        <?php// comments_template( '', true ); ?>
                <form name="input" action="" method="get"></br></br>
                    <input type="text" name="test" width="20" />
                    <input type="submit" value="Submit" />
                </form>
                    <?php endwhile; // end of the loop. ?>

                </div><!-- #content -->
            </div><!-- #primary -->
        <?php get_sidebar(); ?>
        <?php get_footer(); ?>

然后我尝试捕获在不同目录下创建的其他文件中的post数组中的变量值。

在这里,我尝试打印变量。

<?php echo $_POST["test"];?>

虽然url显示类似http://localhost/wordpress/skill/test.php?test=bbbbbbb,我得到404错误。我不能处理word press作为正常的php网站吗?如果没有,实现这一目标的最佳方式是什么?

我不明白:你想在你的网站上添加一个"搜索功能" ?为什么不使用默认值呢?

get search form

和代码<?php echo $_POST["test"];?>不能工作,因为页面上没有test这样的东西。因为这是你的HTML表单:

<form name="input" action="" method="get">

注意:method="get"你不能说表单将使用get方法然后使用Post来获取表单的内容