Forums

Query for multiple tags, how to exclude duplicates (4 posts)

  1. Boris
    Member
    Posted 7 months ago #

    I need to do a query that retrieves posts from a single category, and from several tags (being all tags of the currently opened single post) and places this in a sidebar. I've found a large part of the code already here, and adapted it here and there (such as the addition of a custom field for thumbnails). There's only one problem: some posts have more than one tag in common with the currently opened single post, resulting in duplicate post results.

    I've been trying different solutions (such as described here), but can't get it to work with my limited PHP knowledge. Can someone tell me what is missing from the code?

    [Code moderated as per the Forum Rules. Please use the pastebin]

    Thanks for your help!

  2. Boris
    Member
    Posted 7 months ago #

    Sorry, wasn't aware of the restriction on lines of code. The code can be seen here:
    http://pastebin.com/QaUjX1u5

    Anyone out there who can help me sort this out? I've found quite a few solutions but they're all inside the loop, where this script runs outside of the loop.

    Thank you!

  3. Boris
    Member
    Posted 7 months ago #

    Still working on a solution, but it's proving very difficult. I'll explain what it is I'm trying to accomplish:

    * I have posts in 3 different categories: A, B and C
    * Each post has multiple tags, these tags are used by posts in all three categories.
    * Example: Post1 in CatC has three tags: a1, a2 and b1. Post2 in CatA has 3 tags: a1,b1 and b2. Post3 in CatB has 3 tags: a1,a2 and b1.
    * When I'm looking at Post1, I want two sidebars. One of them shows CatA posts with tags shared with Post1, the other shows CatB posts with tags shared with Post1.
    * I have everything working, except that Post3 shows up twice, because it shares tags a1 AND a2.
    * All of these sidebar posts are shown using thumbnails.

    What I guess is missing from the PHP code, is that I tell the script to look for duplicate PostID's in the query results, and then to discard them. But my PHP knowledge is too basic. I've tried a hundred ways (found in various threads here on the forum and elsewhere on the Internet), but I keep getting those d*mn duplicates! It's almost a relevant posts plug-in thing, but I haven't found any who'll allow me to use multiple widgets where each widget instance allows for including/excluding categories and tags.

    I hope someone can help me out here. In the meantime, I'll keep searching, and will post updates if there are any.

  4. Boris
    Member
    Posted 7 months ago #

    Hello? Anyone? Pretty please with sugar on top? :-)

Reply

You must log in to post.

About this Topic