中查询多个自定义分类术语

中查询多个自定义分类术语

本文介绍了在 Wordpress 2.8 中查询多个自定义分类术语?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个名为技术"的自定义分类法,但无法像使用类别或标签那样查询多个术语.

I created a custom taxonomy named 'technologies' but cannot query multiple terms like I can with categories or tags.

这些查询确实有效:

query_posts('tag=goldfish,airplanes');

query_posts('technologies=php');

但是,以下两种方法都不能正常工作:

query_posts('technologies=php,sql');

query_posts('technologies=php&technologies=sql');

我的目标:显示所有使用'php'技术的帖子和所有使用'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!

推荐答案

显然 query_posts 在这种特定情况下无法提供帮助.(希望它会添加到 Wordpress 的未来版本中!)解决方案是使用自定义选择查询,如下所示:

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:

SELECT *
FROM $wpdb->posts
LEFT JOIN $wpdb->term_relationships ON($wpdb->posts.ID = $wpdb->term_relationships.object_id)
LEFT JOIN $wpdb->term_taxonomy ON($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
LEFT JOIN $wpdb->terms ON($wpdb->term_taxonomy.term_id = $wpdb->terms.term_id)
WHERE $wpdb->posts.post_type = 'post'
AND $wpdb->posts.post_status = 'publish'
AND $wpdb->term_taxonomy.taxonomy = 'technologies'
AND $wpdb->terms.slug = 'php' OR $wpdb->terms.slug = 'css'
ORDER BY $wpdb->posts.post_date DESC

可以在 Wordpress Codex 中找到更多信息:http://codex.wordpress.org/Displaying_Posts_Using_a_Custom_Select_Query

More information can be found at the Wordpress Codex:http://codex.wordpress.org/Displaying_Posts_Using_a_Custom_Select_Query

这篇关于在 Wordpress 2.8 中查询多个自定义分类术语?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 19:05