当要检索帖子时,应该打电话WP_Query.
WP_Query
已调用参数meta_query
但它没有comment_query
.
所以可能需要一个技巧来实现你想要的,
$args = array();
$args[\'feed\'] = 1;
$args[\'withcomments\'] = 1;
$args[\'author\'] = 1; //author id.
$query = new WP_Query($args);
$posts = $query->posts;
//do what you want
wp_reset_postdata();
请注意,$args可能需要更多值,例如post\\u status和posts\\u per\\u page。我只是给你一个大概的想法。
它将生成两个SQL查询:
SELECT wp_comments . *
FROM wp_comments
JOIN wp_posts ON ( wp_comments.comment_post_ID = wp_posts.ID )
WHERE comment_approved = \'1\'
AND (
wp_posts.post_author =1
)
AND wp_posts.post_type = \'post\'
AND (
wp_posts.post_status = \'publish\'
OR wp_posts.post_status = \'private\'
)
GROUP BY wp_comments.comment_id
ORDER BY comment_date_gmt DESC
SELECT SQL_CALC_FOUND_ROWS wp_posts.ID
FROM wp_posts
WHERE 1 =1
AND wp_posts.ID
IN ( 528, 1 )
ORDER BY wp_posts.post_date DESC
LIMIT 0 , 10
第二个SQL查询将通过从第一个SQL返回的POST ID检索POST。
我建议对您的任务使用自定义SQL查询
SELECT wp_posts . *
FROM wp_posts
JOIN wp_comments ON ( wp_comments.comment_post_ID = wp_posts.ID )
WHERE comment_approved = \'1\'
AND (
wp_posts.post_author =1
)
AND wp_posts.post_type = \'post\'
AND wp_posts.post_status = \'publish\'