PHP / Wordpress在搜索输入中显示用户搜索查询

时间:2017-12-08 23:48:36

标签: php wordpress

我正在尝试创建自定义的index.php页面,并希望将用户搜索结果保存在搜索框内。这是我在一起工作的一点点:

<li class="result-searh"><form role="search" method="get" id="searchform" class="searchform" action="http://droogle.dil/">
                <div>
                    <input type="text" value=<?php printf( esc_html__( '%s', stackstar ), '<span>' . get_search_query() . '</span>' ); ?> name="s" id="s">
                    <input type="submit" id="searchsubmit" value="Search">
                </div>
            </form></li>

看起来像这样:

my searcg

当我搜索&#34;我的搜索&#34;。如你所见,它正在出现。看起来有点滑稽。我对PHP非常糟糕,所以如果这看起来很糟糕,请原谅我。我弗兰肯斯坦使用其他插件将这段代码放在一起&#39;代码。

-

编辑:改为:

<input type="text" value=<?php printf( esc_html__( '%s', stackstar ), get_search_query()); ?> name="s" id="s">

现在当我搜索&#34;你好我是乔&#34;检查元素给了我这个:

<input type="text" value="hello" I="" am="" joe="" name="s" id="s">

1 个答案:

答案 0 :(得分:1)

走出未经测试的肢体并建议将<php .. ?>用双引号括起来可能会解决这个问题:

<input type="text" value="<?php printf( esc_html__( '%s', stackstar ), get_search_query()); ?>" name="s" id="s">