简体   繁体   English

如何在WordPress中使用WP_query搜索帖子标题和标签?

[英]How can I search the post title and tag using WP_query in wordpress?

I am currently implementing a search function to search the post from wordpress 我目前正在实现搜索功能,以从wordpress中搜索帖子

I would like to search the post by Tag , by title and return it as JSON 我想按Tag,标题搜索帖子并将其返回为JSON

I found a plugin that generates the result as JSON (JSON API) 我找到了一个将结果生成为JSON(JSON API)的插件

http://wordpress.org/plugins/json-api/other_notes/#2.1.-Core-controller-methods http://wordpress.org/plugins/json-api/other_notes/#2.1.-Core-controller-methods

In that plugin , there is a get_posts function that can return the query that supports WP_query parameter 在该插件中,有一个get_posts函数可以返回支持WP_query参数的查询。

I tried a query like that 我尝试过这样的查询

http://MyWordpressSite.com/?json=get_posts&status=published&orderby=date&order=DESC&lang=en&s=eng&tag=eng&cat=9,10,14,15 http://MyWordpressSite.com/?json=get_posts&status=published&orderby=date&order=DESC&lang=en&s=eng&tag=eng&cat=9,10,14,15

where the &s= is the keyword to search while the &tag= is the tag to search 其中&s =是要搜索的关键字,而&tag =是要搜索的标签

However, there are two problems 但是,有两个问题

  1. How can I limit the search to title only? 如何将搜索限制为仅标题? http://codex.wordpress.org/Class_Reference/WP_Query#Search_Parameter http://codex.wordpress.org/Class_Reference/WP_Query#Search_Parameter

From the official website, it state search keyword ,but not limit to title only 在官方网站上,它指出了搜索关键字,但不仅限于标题

  1. It seems the condition is tag "AND" keywords are match, but what I would like to achieve is tag "OR" keywords are match 看来条件是标签“ AND”关键字匹配,但我想实现的是标签“ OR”关键字匹配

http://codex.wordpress.org/Function_Reference/get_posts http://codex.wordpress.org/Function_Reference/get_posts

So, to sum up , the goal is to search the post by Tag , by title and return it as JSON (actually is call the php through JSON), it doesnt matter using the plugin or not, any way achieve the goal is welcomed. 因此,总而言之,目标是按Tag搜索标题,并按标题搜索,然后将其返回为JSON(实际上是通过JSON调用php),无论是否使用插件,都欢迎以任何方式实现目标。 Thanks for helping 感谢您的帮助

I looked into plugin functions, This plugin does not support to get posts from multiple category. 我研究了插件功能,该插件不支持从多个类别获取帖子。 It just get one category by ID and return the posts and this category info. 它只是通过ID获得一个类别,然后返回帖子和该类别信息。 You need to make a custom plugin or try another to do this task. 您需要制作一个自定义插件或尝试另一个插件来执行此任务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM