• Hello,

    I’ve got 2 connected CPTs: Project and Testimonial, it’s a many-to-many connection.

    I’ve got the following situation where I want to select all the projects that have got testimonials connected. However, if there are multiple testimonials, let’s say 3, are connected to a project then I end up having that project in my results 3 times.

    I want to select unique / distinct projects in case there multiple testimonials are connected to it.

    Is there a way to do it? To choose unique / distinct posts or group them by ID? I can’t figure out.

    Here is what I’ve got so far:

    $args = array(
    		'post_type' => 'project',
    		'order' => 'ASC',
    		'orderby' => 'menu_order',
    		'posts_per_page' => -1,
    		'connected_type' => 'project_to_testimonial',
    		'connected_items' => 'any',
    		'connected_direction' => 'to',
    		'post__in' => <ids_of_specific_projects>,
    	);

    I would hugely appreciate any tips and pointers.

    Many thanks, Dasha

    https://www.ads-software.com/extend/plugins/posts-to-posts/

  • The topic ‘Group posts by ID or distinct, unique posts’ is closed to new replies.