我有一个显示用户发布的类别的查询。例如,如果我有3只猫,名字是新闻、媒体、出版物,而作者只在前两个发布过,它会显示
消息
媒体
有没有比这更好的代码,或者有什么改进,因为我的db真的很大,它会让我感到窒息?非常感谢。
<?php
$author = get_query_var(\'author\');
$categories = $wpdb->get_results("
SELECT DISTINCT(terms.term_id) as ID, terms.name
FROM $wpdb->posts as posts
LEFT JOIN $wpdb->term_relationships as relationships ON posts.ID = relationships.object_ID
LEFT JOIN $wpdb->term_taxonomy as tax ON relationships.term_taxonomy_id = tax.term_taxonomy_id
LEFT JOIN $wpdb->terms as terms ON tax.term_id = terms.term_id
WHERE posts.post_author = \'{$post->post_author}\' ");
?>
<ul>
<?php foreach($categories as $category) : ?>
<?php if ( ($category->ID == \'3\') || ($category->ID == \'4\') || ($category->ID == \'5\')) { ?>
<li>
<a href="<?php echo get_category_link( $category->ID ); ?>/?author_name=<?php echo $curuser->user_login; ?>" title="<?php echo $category->name ?>">
<?php echo $category->name; ?>
</a>
</li>
<?php } ?>
<?php endforeach; ?>
</ul>