Help with WP_Query – searching by many fields
-
Hi all,
I’m trying to use the WP_Query object to do quite a complex search – I’d like to search by the post title, custom taxonomies, and custom fields too. The problem is I’d like to get posts which fulfil ANY, not ALL of the requirements… It’s probably easier to explain with code:
[Code moderated as per the Forum Rules. Please use the pastebin]
So using this object will return posts of the type ‘restaurant’ which have the ‘$search_query’ in the title or text, but only if they ALSO fit the taxonomy requirements listed under tax_query. I’d like to list restaurants which meet EITHER of these requirements – either the text is in the title, or it has the right taxonomy terms, or both.
So… to be specific…
1) How do I list posts which meet either requirment rather than both?
2) For the first requirement, how do I make it search just the post title, and not the whole content text?
3) Can I then add a third requirment, involving meta keys and values, also as an ‘OR’ in the eventual query string?
So essentially I want… in extremely bad pseudo-code/SQL…
WHERE post_title LIKE $var OR [insert taxonomy query here] OR [insert meta key/value query here] ORDER BY whateverAny ideas? Or will I have to write my own custom SQL for this? I’d really rather not if I can possibly help it… :/
Thanks!
J.R.
[No bumping, thank you.]
The topic ‘Help with WP_Query – searching by many fields’ is closed to new replies.