WordPress.org

Ready to get started?Download WordPress

Forums

wp_get_archives, postbypost, duplicates - taxonomy? (4 posts)

  1. llewellynworld
    Member
    Posted 5 years ago #

    I'm having trouble calling the wp_get_archives function using the "postbypost" type. It's returning duplicates and I've tracked it down to the query joining on the wp_term_taxonomy table where there are multiple entries in this table per post. This appears to be because I have multiple categories assigned to some posts. Those assigned to just one category display twice whereas those assigned to multiple categories show even more times.

    Here's how I'm calling the function for my left sidebar/column:

    wp_get_archives('type=postbypost&limit=10');

    Is this supposed to work this way?

    Any ideas greatly appreciated!

    ~ Jenifer

  2. MichaelH
    Member
    Posted 5 years ago #

    Using the WordPress Default Theme, no plugins active, changed sidebar.php to use<?php wp_get_archives('type=postbypost&limit=4'); ?> and it did NOT duplicate any posts, even if the posts had 1,2, or 3 categories assigned.

    Wonder if you have a plugin causing that problem?

  3. llewellynworld
    Member
    Posted 5 years ago #

    hmm... could be. All I had at the time was the Role Scoper plugin and the Top Level Categories plugin installed. Here's the query that the wp_get_archives function is executing:

    SELECT * FROM wp_posts LEFT JOIN wp_term_relationships AS tr ON wp_posts.ID = tr.object_id LEFT JOIN wp_user2role2object_rs AS uro ON uro.obj_or_term_id = wp_posts.ID AND uro.src_or_tx_name = 'post' AND uro.scope = 'object' AND uro.assign_for IN ('entity', 'both') AND uro.group_id IN ('1') WHERE wp_posts.post_date > 0 AND post_type = 'post' AND post_status IN ('publish', 'private') ORDER BY post_date DESC LIMIT 10

    It's the term_taxonomy_id column in the query that's causing the duplicates. I guess I need to figure out what that table is used for and why my install is causing duplicates.

    Jenifer

  4. citizensheep
    Member
    Posted 5 years ago #

    I had exactly the same problem, and as a result of reading this thread I deactivated Role Scoper: which fixed it. Thank you!

    (I've posted this to the plugin's forum.)

    Best wishes,

    Michael

Topic Closed

This topic has been closed to new replies.

About this Topic