sql - Wordpress MySQL 查询帖子类型
问题描述
我想在这个查询中添加 post_type 选项。我该怎么做?
$state = $wpdb->get_results("
SELECT meta_value AS state, COUNT(post_id) AS count
FROM {$wpdb->postmeta} WHERE meta_key = 'personal_nation'
GROUP BY state ORDER BY state DESC");
解决方案
试试这个查询
SELECT meta_value AS state, COUNT(post_id) AS count, post_id
FROM wp_postmeta WHERE meta_key = 'personal_nation'
AND post_id in(select ID from wp_posts where post_type="post")
GROUP BY state ORDER BY state DESC
推荐阅读
- docker - Windows docker-compose 没有输出
- python-3.x - 猪两台电脑游戏
- angular - Angular:将事件添加到在 FormArray 中动态添加的 FormControls
- filter - Julia Iterator 产品和过滤器
- jquery - 制表符 JSON 从服务器返回
- php - 将变量设置为 $_GET 值时遇到问题
- python - 如何使用 Python 在 Watson Discovery 中过滤查询结果?
- javascript - 是否有多次分配 window[functionName] = functionName 的简写?
- sql-server - 外键断言的聚集索引扫描
- php - $DBSERVER 是什么以及如何在 config.php 中进行配置?