WordPress.org

Ready to get started?Download WordPress

Forums

Tags being used as categories by WP (9 posts)

  1. stml
    Member
    Posted 6 years ago #

    Just found a weird effect on a lage site I manage. I recently upgraded to 2.3.1 and have not implemented tags on the site, but users have started to tag articles.

    The site, http://www.3ammagazine.com/3am/, is organised by categories, and each article is in only one category. However, we've discovered that if an article is tagged with the name of a category, it appears in this category too.

    e.g. an article in the Interviews category (cat 2) is tagged (among other things) 'fiction'. However, when the latest Fiction category articles are called with

    $myposts = get_posts('numberposts=3&category=5');

    the article is called by $myposts here too.

    Why is this happening, is it intended, and if so, why? I'm sure tags and categories are meant to be different systems.

  2. Kafkaesqui

    Posted 6 years ago #

    It is not intended. Looks like get_posts() is a bit buggy here. I'll report it, but for now there's two options to get around the bug:

    1. Follow the examples here:

    http://codex.wordpress.org/The_Loop#Multiple_Loops

    for using query_posts() or the WP_Query() class to set up your category loops.

    2. Fix the bug!

    If you're up to editing the WordPress core, get_posts() is defined in wp-includes/post.php. At or around line 257 in post.php you'll find this line:

    $query .= empty( $category ) ? '' : "AND ($wpdb->posts.ID = $wpdb->term_relationships.object_id AND $wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id AND $wpdb->term_taxonomy.term_id = " . $category. ") ";

    Change it to the following:

    $query .= empty( $category ) ? '' : "AND ($wpdb->posts.ID = $wpdb->term_relationships.object_id AND $wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id AND $wpdb->term_taxonomy.term_id = " . $category. " AND $wpdb->term_taxonomy.taxonomy = 'category') ";

    Source editing note: Back up files before editing.

    EDIT: Already reported - http://trac.wordpress.org/ticket/5317

  3. MichaelH
    Member
    Posted 6 years ago #

  4. Kafkaesqui

    Posted 6 years ago #

    Jinx...

    I'll post the fix in the ticket.

  5. stml
    Member
    Posted 6 years ago #

    Good to know, and thanks for the info. I'm not going to edit the core, but this seems like a pretty serious thing to me, and I'm surprised it's possible to confuse tags and categories this easily... it suggests all the implications of adding tags to WP haven't been fully thought out.

    (I speak as a massive WP fan...)

  6. MichaelH
    Member
    Posted 6 years ago #

    WordPress depends on volunteers to test the software so please consider joining the fun.

    Mailing_Lists has a link to the wp-testers email list. Reporting_Bugs describes the process of reporting a bug.

  7. Kafkaesqui

    Posted 6 years ago #

    stml, no matter how well thought out anything regarding software is, bugs will creep in. It doesn't matter how good the developers are, or how much pre-testing is done on the various parts of an application. Bugs will show up.

  8. stml
    Member
    Posted 6 years ago #

    I put in that 'massive WP fan' comment to deflect those replies! I'm aware bugs will creep in - what I'm saying is that I'm surprised that tags were implemented in a way that this could happen. It's criticism, not an attack.

    Have joined wp-testers as I implement on average a couple of WP installs a month, and do want to give something back...

  9. Roar
    Member
    Posted 6 years ago #

    Thank you, editing the core worked and was not very painful at all!

Topic Closed

This topic has been closed to new replies.

About this Topic