如何更改搜索查询?
我已经为我的网站之一安装了即时问答 WordPress 主题。有一个“查找问题”搜索框,我想更改在后台运行的检索记录的查询。我附上相同的屏幕截图。我发现有一个 searchform.php 正在加载搜索表单,但我无法跟踪获取记录的代码。
请帮助我解决这个问题。
谢谢,
潘卡杰
I have installed Instant Q&A wordpress theme for one of my website. There is a Find a Question search box, i want to change the query which runs in the background that is which retrieves the records. I am attaching the screen shot of the same. I have traced that there is a searchform.php which is loading the search form but i am unable to trace the code which fetches the records.
Please help me on this.
Thanks,
Pankaj
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
searchform.php 仅包含搜索表单的 html 模板。另外,在您的模板中(可能)您有 search.php,它是搜索结果的另一个模板。但查询不是模板的一部分,并且在 WordPress 代码中修改它们有点困难。
但是,只需将输入字段添加到 searchform.php 就可以成为您的解决方案。举个例子,如果您想在类别中搜索具有给定关键字(搜索字段)的帖子,您可以添加到您的 searchform.php 中:
我猜(但我不确定)您可以像您一样使用任何查询变量与query_posts()。
searchform.php contains just an html template for the search form. Also in your template (probably) you have search.php that is another template for the search results. But the queries are not part of the templates and they are a bit hard to modify inside the wordpress code.
But, just adding input fields to searchform.php can be a solution for you. As an example, if you want to search for posts with a given keyword (search field) inside a category, you can add to your searchform.php:
I guess (but I am not sure) you could use any query var as you do with query_posts().