如何修改 WordPress 中的搜索查询? [英] How do I modify a search query in WordPress?

查看:50
本文介绍了如何修改 WordPress 中的搜索查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 WordPress 并且在标题中有一个搜索框.它根据帖子进行搜索.现在我想用一个城市下拉搜索框修改这个搜索框.我还在数据库中添加了一个新的城市表.我需要根据城市运行搜索框.

I am using WordPress and have a search box in the header. It searches on the basis of posts. Now I want to modify this search box with a cities drop down search box. I also added a new cities table in the database. I need to run the search box on the basis of cities.

推荐答案

如果您为位置制作了一个特殊的表格,您可能需要自己的搜索查询并从该查询开始开发您的需求.

If you have made a special table for locations you are probably going to need your own search query and start from that one to develop your needs.

一个好的开始是创建一个新的模板文件,您将向其中提交搜索表单,并在 functions.php 中创建一个搜索功能,这是您主题中的必需文件.

A good start would be to create a new template file to which you are going to submit your search form, and a search function in functions.php which is a mandatory file in your theme.

我在在 WordPress 中搜索多个自定义字段.

但是,您可能会问:为什么需要为此编写特殊的搜索功能?您说您在数据库中添加了一个新表,该表不属于 WordPress 默认分类系统的一部分,因此不会考虑您的额外搜索参数.

However, you might ask: Why do you need to write a special search function for that? You said you have added a new table in the database that is not part of the default taxonomy system of WordPress so that one is not going to take into consideration your extra parameters of the search.

此外,我不建议您修改核心搜索功能,因为在某些特定时间,您可能希望进行升级,这会干扰您的搜索.functions.php 文件方式更安全,生成结果更快.

Moreover I do not recommend you to modify the core search function, because at some particular time you would probably like to make an upgrade or so, and that is going to mess up with your search. The functions.php file way is the safer way and yields results faster.

这篇关于如何修改 WordPress 中的搜索查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆