自定义查询:多种自定义帖子类型
我在从 自定义 WordPress 查询 中提取多个自定义帖子类型时遇到一些问题。我创建自定义 WordPress 查询而不是使用 query_posts
或 WP_query
的原因是因为我根据投票插件添加的信息对帖子进行排序,并且必须加入该查询插件的表,因此内置查询不是一个选项。
我的问题是如何在同一查询中包含多个自定义帖子类型?目前,我的查询如下所示:
$query = "
SELECT wposts.*
FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
WHERE wposts.ID = wpostmeta.post_id
AND wposts.post_status = 'publish'
AND wposts.post_type = 'TWO_POST_TYPES'
AND post_date >= '$startdate'
AND post_date <= '$enddate'
GROUP BY wposts.ID
";
我试图将两种不同的自定义帖子类型放入 wposts.post_type
部分,我们可以将其称为 type1
和 类型2。我已经尝试过以下内容,但没有成功:
array('type1', 'type2')
'type1, type2'
我也尝试过传递这两个作为查询中的变量,但也没有运气。有人可以帮我吗?
I am having some trouble pulling multiple custom post types from a Custom Wordpress Query. The reason I am creating a custom Wordpress query rather than using query_posts
or WP_query
is because I am sorting my posts based on information added by a voting plugin, and have to join that plugin's table, so the built-in queries are not an option.
My question is how can I include multiple custom post types in the same query? At present, my query looks like the following:
$query = "
SELECT wposts.*
FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
WHERE wposts.ID = wpostmeta.post_id
AND wposts.post_status = 'publish'
AND wposts.post_type = 'TWO_POST_TYPES'
AND post_date >= '$startdate'
AND post_date <= '$enddate'
GROUP BY wposts.ID
";
I am trying to put two different custom post types into the wposts.post_type
part, which we can call type1
and type2
. What I have already tried is the following, with no luck:
array('type1', 'type2')
'type1, type2'
I have also tried passing both of these as variables in the query, but also no luck. Would anybody be able to give me a hand?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你是这个意思吗?
这实际上意味着:
Do you mean this?
which actually means: