【问题标题】:Get search text value in URL获取 URL 中的搜索文本值
【发布时间】:2013-10-11 05:23:10
【问题描述】:

我有这样的表格

<form method="get" id="searchform" action="http://domain.com">
    <input name="s" id="s" type="text" />
    <input type="submit" id="searchsubmit" type="submit" />
</form>

当我在搜索输入文本中添加一些关键字时,URL 将变为http://domain.com/?s=keyword

我需要http://domain.com/?s=keyword&post_type=events

意味着我只需要在 url 上添加 &post_type=event。我该怎么做?有什么建议吗?

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    添加隐藏字段

    <input type="hidden" name="post_type" value="events">
    

    【讨论】:

    • 非常感谢。这是工作。我会在 8 分钟内接受你的回答。
    【解决方案2】:

    请试试这个代码...

    <form method="get" id="searchform" action="http://domain.com">
        <input name="s" id="s" type="text" />
        <input type="submit" id="searchsubmit" name="post_type" value='event'/>
    </form>
    

    当你按下按钮它返回喜欢。

    http://domain.com/?s=keyword&post_type=events
    

    【讨论】:

    • 谢谢。它也在工作。了解名称和值功能:)
    • 这是不可取的。隐藏输入字段会更好。这也将提交按钮上的文本更改为event,而它应该是search
    • 你是对的。我在提交按钮上使用搜索图标,所以没有问题。但是,是的,隐藏会更好:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-12
    • 2012-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多