• Blog
  • Archives
  • Code
  • Talks
  • About

Page-Tags 0.2

Note: This post is over 2 years old and may now be out of date. Some of the links not work anymore.

(1 minute read)

A recently noticed issue with the Page-Tags plugin was that if you added a new tag when editing a page the tag didn't show up in the tag cloud sidebar widget. Only tags which were also associated with one or more blog posts were showing up in the tag cloud. I was seeing the same problem on my archives page.

This issue has now been fixed in the latest version. To get the tags you've already added showing, install the updated plugin, and then edit and save the corresponding pages without making any changes.

For the developers among you, the cause of this bug is situated the callback function used to calculate how many posts are linked to a given tag:

function _update_post_term_count( $terms ) {
  global $wpdb;

  foreach ( (array) $terms as $term ) {
    $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships, $wpdb->posts WHERE $wpdb->posts.ID = $wpdb->term_relationships.object_id AND post_status = 'publish' AND post_type = 'post' AND term_taxonomy_id = %d", $term ) );
    $wpdb->update( $wpdb->term_taxonomy, compact( 'count' ), array( 'term_taxonomy_id' => $term ) );

As you can see it only counts blog posts. Page-Tags 0.2 simply replaces this callback function with one which also counts pages.

Note: The sidebar tag cloud widget will only show the top 45 tags (see the documentation for the wp_tag_cloud function).