简体   繁体   中英

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

I would like to search the post by Tag , by title and return it as JSON

I found a plugin that generates the result as JSON (JSON API)

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

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

where the &s= is the keyword to search while the &tag= is the tag to search

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

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

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. 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. You need to make a custom plugin or try another to do this task.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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