$post = $wpdb->get_results("SELECT `p`.`ID`, MAX(p.post_date) as `datetime`, `p`.`post_date`, `p`.`post_content`, `p`.`post_title`, `p`.`post_status`, `p`.`post_name`, `p`.`comment_count`, `tax`.`term_taxonomy_id`, `tax`.`term_id`, `tax`.`taxonomy`, `tax`.`parent`, `rel`.`object_id`, `rel`.`term_taxonomy_id`, `t`.`term_id`, `t`.`name`, `t`.`slug`
FROM (`$wpdb->posts` AS p)
INNER JOIN `$wpdb->term_relationships` AS rel ON `rel`.`object_id` = `p`.`ID`
INNER JOIN `$wpdb->term_taxonomy` AS tax ON `tax`.`term_taxonomy_id` = `rel`.`term_taxonomy_id`
INNER JOIN `$wpdb->terms` AS t ON `t`.`term_id` = `tax`.`term_id`
WHERE `tax`.`taxonomy` = 'category'
AND `p`.`post_status` = 'publish'
AND `p`.`post_type` = 'post'
GROUP BY tax.parent
ORDER BY datetime DESC
LIMIT 4");
各カテゴリの最新の投稿を見つけて、結果をグループ化する必要があるため、各カテゴリの最新の投稿は 1 つだけです。
私は使用します。GROUP BY tax.parent
動作しません;ORDER BY datetime DESC