Tet banner

Custom Fields
Support MB Relationships Duplicate posts returned from relationship query

  • Creator
  • #14719
    Resolved ecurtain

    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

    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?


Viewing 1 replies (of 1 total)
  • Author
  • #14764
    Anh Tran

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

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.