Skip Navigation

[Resolved] Split: search terms in custom field – list parent post only once

This thread is resolved. Here is a description of the problem and solution.

Problem:
list parent post only once when listing child posts OR Group by parent posts when listing/displaying/showing child posts.

Solution:
You can use the View's filter hook "wpv_filter_query_post_process" to group child posts by parent posts.

You can find the proposed solution in this case with the following reply:
=> https://toolset.com/forums/topic/split-search-terms-in-custom-field-list-parent-post-only-once/#post-2000697

Relevant Documentation:
=> https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query_post_process

This support ticket is created 3 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.

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 7 replies, has 2 voices.

Last updated by davidm-13 3 years, 9 months ago.

Assisted by: Minesh.

Author
Posts
#2000543

Yes, Thanks very much.
I see the child posts, how would I change this to see a list of unique parent post titles.
Also how would I search for phrases eg. "abdominal pain"

Thanks

#2000567

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Can you please send me admin as well as FTP access details.

I have set the next reply to private which means only you and I have access to it.

#2000655

Minesh
Supporter

Languages: English (English )

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

I tried to update the function.php file and for couple of time the FTP works and now I just cant connect to the FTP.

Looks like as I'm changing the file and upload it again server blocked me or not sure why its not allowed me to connect to FTP.

Can you please remove any blockages and then I will try to connect the FTP again.

#2000665

Please can you try again.
Seems there were problems on the server but they seem to have resolved themselves

#2000697

Minesh
Supporter

Languages: English (English )

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

Can you please check now. I can seen that child posts are grouped by parent.

I've added the following code to your current theme's functions.php file:

add_filter( 'wpv_filter_query_post_process', 'func_group_by_parent_post', 999, 3 );
function func_group_by_parent_post( $query, $view_settings, $view_id ) {
   
    if ($view_id == 42582) { 
	
	$parent_ids = array();
    if ( !empty( $query->posts ) ) {
          
               $all_posts = $query->posts;
            foreach($all_posts as $k=>$v):
                
           $get_parent =  toolset_get_related_post($v->ID,'plant-complaint');
       
             if(!in_array($get_parent,$parent_ids)){
                    $parent_ids[$get_parent] = $get_parent;
             }else{ 
               unset($all_posts[$k]);
             }
              endforeach;
              $query->posts = array_values($all_posts); 
             $query->found_posts = count($all_posts); 
              $query->post_count =  count($all_posts); 
               
    }        
  }

    return $query;
}

It was bit crazy issue but I managed to find solution. Can you please confirm you able to see now unique parents.

More info:
=> https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query_post_process

#2000703

Thanks very much Minesh, looks good.
Is there a possibility of looking for phrases eg. "abdominal pain" - if it's enclosed in quotes?
Or tick a checkbox to find child posts where all the words appear, if that's easier
Thanks

#2000717

Minesh
Supporter

Languages: English (English )

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

Relevanssi offers the settings under "Advanced indexing settings" => Apostrophes and quotes
=> hidden link

Its on Relevanssi and you will require to consult the Relevanssi about this. Glad to help you 🙂

#2000721

My issue is resolved now. Thank you!