用于从特定类别中选择帖子标题和帖子ID的SQL查询

时间:2013-06-14 作者:Jithesh Kt

我正在寻找SQL查询以选择帖子标题(&A);发布特定类别的ID。我查看了wordpress表的结构,但它确实让我困惑。

1 个回复
最合适的回答,由SO网友:birgire 整理而成

您可以使用

$args = array( \'post_type\' => \'post\' ,\'posts_per_page\' => 10, \'category_name\' => \'orange\' );
$query = new WP_Query( $args );  

printf( \'<h2>Generated SQL:</h2><pre>%s</pre>\', $query->request );
显示生成的SQL 查询上述示例将为您提供:

<h2>Generated SQL:</h2>
<pre>
SELECT SQL_CALC_FOUND_ROWS wp_posts.ID  
FROM wp_posts 
INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) 
WHERE 1=1 
AND ( wp_term_relationships.term_taxonomy_id IN (123) ) 
AND wp_posts.post_type = \'post\' 
AND (wp_posts.post_status = \'publish\' OR wp_posts.post_status = \'private\') 
GROUP BY wp_posts.ID 
ORDER BY wp_posts.post_date DESC 
LIMIT 0, 10
</pre>

结束

相关推荐

通过SQL查找以类型B的A开头的所有帖子

我对post和分类查询有问题。我需要的是从自定义帖子类型中获取所有帖子,该类型以A开头,并定义了术语。以下是我的sql:SELECT * FROM $wpdb->posts, $wpdb->terms WHERE post_title LIKE \'А%\' AND post_type = \'filmi-i-serialii\' AND post_status = \'publish\' AND slug = \'igralni