Skip Navigation

[Resolved] Split: Split: Grouping View results by a field.-add custom search for ride contact field – registration ride leader

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 22 replies, has 2 voices.

Last updated by lesleeM 1 year, 4 months ago.

Assisted by: Minesh.

Author
Posts
#2621723

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I've disabled the filter as given under with the code snippet "remove-duplicates-from-my-riders-view":

//add_filter( 'wpv_filter_query_post_process', 'func_remove_duplicate_my_riders_email', 99, 3 );
function func_remove_duplicate_my_riders_email( $query, $view_settings, $view_id ) {
    if ($view_id==8433 and  !empty( $query->posts ) ) { 
          
      $all_posts = $query->posts;
      static $duplicate_email= array();
      foreach($query->posts  as $k=>$v):
          $current_email = get_post_meta($v->ID,'wpcf-email',true);
        
          if(in_array($current_email,$duplicate_email)){
               $duplicate_index[] =$k; 
           }
          $duplicate_email[] =    get_post_meta($v->ID,'wpcf-email',true);
      endforeach;

if(!empty($duplicate_index)){
foreach($duplicate_index as $k=>$v):
    unset($all_posts[$v]);
endforeach;

}
 
        $query->posts = $all_posts; 
        $query->found_posts = count($all_posts); // modify the count of found posts
        $query->post_count = count($all_posts); // modify the count of displayed posts
    }
    return $query;
}

And added the following filter:

add_filter('posts_groupby', 'group_posts_by_custom_field_remove_duplicates', 99, 2);
function group_posts_by_custom_field_remove_duplicates($groupby, $query) {
    global $wpdb;
global $WP_Views;

if($WP_Views->current_view==8433) {
    $groupby = "{$wpdb->prefix}postmeta.meta_value";
}
    return $groupby;
}

Can you please confirm its working as expected: hidden link

#2621747

You're going to hate me here. This looks good, but I wanted to compare the results on the Kenny Moore page here

hidden link

To what you had working here when the Kenny Moore Ride Leader is selected in the dropdown:

hidden link

And now there is a fatal error on the second page.

I specifically avoided doing anything to the custom code you provided in groupbycontactname. I merely copied it to set up remove-duplicates-from-my-riders-view. But now the view you had working before is broken. I have no idea what caused this.

#2621931

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I've adjusted the code added to code snippet "remove-duplicates-from-my-riders-view" as given under:
=> hidden link

add_filter('posts_groupby', 'group_posts_by_custom_field_remove_duplicates', 99, 2);
function group_posts_by_custom_field_remove_duplicates($groupby, $query) {
    global $wpdb;
global $WP_Views;
//or $WP_Views->current_view==7992
if($WP_Views->current_view==8433 or $WP_Views->current_view==7992) {
    $groupby = "{$wpdb->prefix}postmeta.meta_value";
}
    return $groupby;
}

Also, I've limit the number of posts to display with the following parent view to 1.
=> hidden link

Also I've adjusted the output of parent view's loop content template as given under:

<h3>[types field="ride-contact-2"][/types]</h3>
[wpv-view name="ride-registrations-by-ride-leader-child" wpvrelatedto="[wpv-post-id item='@ride-ride-leader.child']"]

With the child view:
=> hidden link

I've adjusted the query filter as given under:

Filter by post relationship or repeatable fields group owner
Select posts in a Ride Leaders Registrations relationship that are related to the Post with ID set by the shortcode attribute wpvrelatedto.
eg. [wpv-view name="view-name" wpvrelatedto="123"]

Now if you compare the both pages:
- hidden link
- hidden link

The output of your view is the same - can you please confirm it works as expected now.

#2621991

Looks perfect. Thanks again.

Note that this latest flurry of support tickets came about because I have different board members of this club asking me for different features after we have launched. I thought I had everything done, but I'm getting lots of feedback requesting different things. This should subside once this latest round of tickets is done. I have been able to add some things that were requested myself, so I am getting better with this from following everything you guys have shown me even if it doesn't seem like it sometimes.

#2621995

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Glad to help.

You're welcome to create new ticket with every new question you may have. This will help users searching on the forum as well as help us to write correct problem resolution summery.

You are welcome to mark this ticket resolved now with different message that "this ticket is resolved with update".

#2622001

My issue is resolved now. Thanks a bunch!

#2622009

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

You have to mark ticket as resolved 🙂 Thank you.

#2622017

Oops. I thought I did. But it said something about a duplicate post, so I changed it and sent again, but I guess I clicked I still need assistance by mistake.