我想从最近 10 个帖子中获取最近的标签。或者获取最近帖子中使用的最近 100 个标签。我的代码:
<?php
$tags .= "SELECT $wpdb->terms.term_id, $wpdb->terms.name, $wpdb->terms.slug
FROM $wpdb->terms
INNER JOIN $wpdb->term_taxonomy ON ($wpdb->terms.term_id = $wpdb->term_taxonomy.term_id)
INNER JOIN $wpdb->term_relationships ON ($wpdb->terms.term_id = $wpdb->term_relationships.term_taxonomy_id)
INNER JOIN $wpdb->posts ON ($wpdb->term_relationships.object_id = $wpdb->posts.ID)
WHERE $wpdb->term_taxonomy.taxonomy = 'post_tag'
ORDER BY $wpdb->posts.post_date DESC";
$tags= $wpdb->get_results($tags); // $query being the above SQL
foreach ($tags as $tag) {
if (!isset($stack[$tag->term_id]))
$stack[$tag->term_id] = $tag;
}
print_r($stack); // should print an array of all tags, ordered by last used
?>
它不工作。例如,没有指向标签的链接。