WordPress 2.3 - Tagging Posts and Pages

Hi WordPress Community!

Did you have the same weird feeling by giving up Ultimate Tag Warrior or similar? (btw. thanks Christine for your support and greetz to nz) I was a little bit frustrated, that this great piece of work is not supported in WordPress 2.3…

Anyway, first of all it took a long time to update my theme (especially for the mash-ups). And as only posts are supported for tagging, I also had to integrate the built-in tags feature for pages. Importing them from UTW into the new database structure (taxonomy/terms) worked like a charm. A few days after the new WordPress version was released, I found a plugin on Michele’s blog which adds the necessary where-statement (as well as the tags section in page edit of the WordPress admin menu) for associating pages and not only posts with tags, but I still missed the pages tags in the tag_cloud.

So, the final piece of work was to find out how to change the sql-select statements to get a full-tag cloud. Unfortunately, as far as I know, it is not possible to encapsulate this functionality in a WordPress plugin. you have to change your taxonomy.php (in wp-includes) manually. Thus, you have to do it again after every wordpress-update. – to the wordpress developers: would it be possible to include an option-field to select if not only post, but also pages should be tagged in future WordPress versions? – Anyway, in the mean-time change the two code-lines (which include the post_type attribute in the select-statement) as stated below. And don’t forget to add or delete a tag, because the tag_cloud is based onWordPress cache!

Statement 1 original code:

$results = $wpdb->get_results("SELECT object_id, term_taxonomy_id FROM $wpdb->term_relationships LEFT JOIN $wpdb->posts ON object_id = ID WHERE term_taxonomy_id IN (".join(',', array_keys($term_ids)).") AND post_type = 'post' AND post_status = 'publish'");

Statement 1 modified version:

$results = $wpdb->get_results("SELECT object_id, term_taxonomy_id FROM $wpdb->term_relationships LEFT JOIN $wpdb->posts ON object_id = ID WHERE term_taxonomy_id IN (".join(',', array_keys($term_ids)).") AND post_type IN ('post', 'page') AND post_status = 'publish'");

Statement 2 original code:

$count = $wpdb->get_var("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 = '$term'");

Statement 2 modified code:

$count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->term_relationships, $wpdb->posts WHERE $wpdb->posts.ID = $wpdb->term_relationships.object_id AND post_type IN ('post', 'page') AND post_status = 'publish' AND term_taxonomy_id = '$term'");

That should do the job. – Btw. the plugin from cybernet provides a useful click-list with all your tags in the edit section of the wordpress admin menu.

greetz berny

4 Responses to “WordPress 2.3 - Tagging Posts and Pages”

  1. leoniedu
    leoniedu
    leoniedu probably commented in United States says:

    I had to modify the following lines as well. Did you have the same problem?

    unction _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 in (‘post’,’page’) AND term_taxonomy_id = %d”, $term ) );
    $wpdb->update( $wpdb->term_taxonomy, compact( ‘count’ ), array( ‘term_taxonomy_id’ => $term ) );
    }
    }

  2. Berny
    Berny
    Berny probably commented in Austria says:

    hi leoniedu,

    you’re right. – i assume that your code derives from the 2.8 branch? – the statements which one needs to modify changed during the last years…

    basically on new wordpress versions i always look for all occurrences of post_type = 'post' in taxonomy.php and change them to post_type IN ('post', 'page').

    that’s still a hassle, but it looks like there is no other easy way, as the wp guys still refuse to use tags for pages.

    greetz,
    berny

  3. Berny
    Berny
    Berny probably commented in Thailand says:

    The follow-up of this post for WordPress 3.0 can be found here.

  4. TagPages review, discussions, does it work, and ratings on Loadwp.com | Loadwp.com this pingback probably came from The Netherlands says:

    […] plugin is a follow-up to my post which I wrote a few years ago. – The idea was (and still is) to equip pages with tags and […]

Leave a Reply

You must be logged in to post a comment.