我正在尝试创建一个wpdb查询,该查询返回标题以某个字母开头且属于某个类别的所有帖子。到目前为止,我有这个:
$answer = $wpdb->get_results("SELECT * FROM wp_posts WHERE SUBSTRING(post_title,1,1)='T' AND post_type='post'");
这将返回以字母 T 开头的所有帖子。这很好,但是,我想比这更狭隘。我只想显示属于特定类别ID的那些。
类别ID似乎不是 wp_posts 表中的字段。如何访问它并将其插入我的SQL语句?
-------的修改 -----
没关系,弄清楚了。
这是:
$answer = $wpdb->get_results("SELECT post_title, post_content, term_taxonomy_id FROM wp_posts LEFT JOIN wp_term_relationships ON wp_posts.ID = wp_term_relationships.object_id WHERE SUBSTRING(post_title,1,1)='T' AND term_taxonomy_id=6");
答案 0 :(得分:0)
$answer = $wpdb->get_results("SELECT post_title, post_content, term_taxonomy_id FROM wp_posts LEFT JOIN wp_term_relationships ON wp_posts.ID = wp_term_relationships.object_id WHERE SUBSTRING(post_title,1,1)='T' AND term_taxonomy_id=6");