本文介绍了在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