Duplicate posts returned from relationship query

Support MB Relationships Duplicate posts returned from relationship queryResolved

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #14719
    ecurtainecurtain
    Participant

    In our product we have custom post types for "products" and "groups", and an mb_relationship "product_to_group"

    On the group archive page, we want to include products linked to current group as well as the group's children.

    So the archive code first generates an array containing the group id, and the group's children's id's.
    $group_array = array(1,2,3,4); // where 1=current id; 2,3,4=children

    The we perform our main query:

        $the_query = new WP_Query( array (
            'post_type'      => 'product',
            'post_status'  => 'publish',
            'posts_per_page' => -1,
            'relationship' => array(
                'id' => 'product_to_group',
                'to' => $group_array, 
            ),
        ) );
    
        if ( $the_query->have_posts() ) {
    
            while ( $the_query->have_posts() ) : $the_query->the_post(); 
    
                // Process the post
    
            endwhile; 
    
        }
    

    The problem we are seeing is duplicate products. I think what's happening is if a product is in multiple groups, it appears in the results for each matching group.

    My workaround will be to use a $used_products array to skip over duplicates, but this feels like a band-aid.

    Am I using the plugin incorrectly? Is this a bug / feature?

    Thanks

    #14764
    Anh TranAnh Tran
    Keymaster

    Hi, it's a bug when running the SQL. I've just fixed it here. Can you try it?

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.