I created a custom taxonomy named ‘technologies’ but cannot query multiple terms like I can with categories or tags.
These querys DO work:
query_posts('tag=goldfish,airplanes');
query_posts('technologies=php');
However, neither of the following work correctly:
query_posts('technologies=php,sql');
query_posts('technologies=php&technologies=sql');
My objective: Show all posts with a technology of ‘php’ and all posts with a technology of ‘sql’
Any ideas? Is this even possible? Thanks!
Apparently query_posts cannot help in this specific situation. (Hopefully it will be added in future versions of WordPress!) The solution is to use a custom select query like the following:
More information can be found at the WordPress Codex:
http://codex.wordpress.org/Displaying_Posts_Using_a_Custom_Select_Query
This is a bit of a delayed reply, but it’s first on Google at the moment for “wordpress related posts by multiple terms” so thought I’d contribute my findings.
Since this question was posted WordPress has been changed to allow for this type of query. This will give you a list of posts related by any of the custom taxonomy terms assigned to an object:
This is my first contribution to SO, I hope it’s up to standards.
You can use this plugin:
http://scribu.net/wordpress/query-multiple-taxonomies/
Does this work? query_posts(‘tag=bread+baking+recipe’)
From: http://codex.wordpress.org/Template_Tags/query_posts
OK, so here is my crack at this. It’s a little hacky, but it works. The big downside is that any other query variables need to be re-added, as when multiple terms are invoked, the fail strips out all of the query vars.
Also, I did not test this against querying across multiple taxonomies. This only works within a specific taxonomy. Use at your own risk.
It’s somehow silly that after implementing custom taxonomies in WP there are no built-in functions to use them at will, and the documentation is close to non-existent. I was looking for a solution, this query solves it (and made my day). Thanks.
Still, sadly I’m too dumb (OOP blind) to make it into a function so I don’t repeat it all over.
I get:
**Fatal error**: Call to a member function get_results() on a non-object
I guess I don’t know how to call $wpdb from within a function.
it should be like this:
that works for custom post_types, at least.
Hey, I also faced the same problem once. If you don’t have many multiple values, then you can do it in the following way, rather than writing a raw SQL query:
Then you can loop through the wp_query object created here.
Though this is a very old post and am sure you have already solved the problem. 🙂