Skip Navigation

[Resolved] Wrong title ordering

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 4 replies, has 1 voice.

Last updated by pierre-yvesC 2 days ago.

Assisted by: Minesh.

Author
Posts
#2834730

I have a strange behaviour on a view:

The view is displaying child posts, ordered by parent title.

This works perfectly, except the 1st item of the list is always the one with parent's title «Réplique Estrie», which is far to begin with A.

I deleted this parent and recreated it and the behaviour is still going.

You can see it there: hidden link

In the same view, I have a test parent called "AAAA 7 nov". This post should be the first but is not.

Any idea?

Thx

#2834892

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

The thing is that you can set the ordering for post title based on the current post title, having said that it should be order by the post titlte of post type you set your view to query.

I'm not sure how you set the ordering that order by the parent post title.

#2834956

Hello Minesh,

Thx for you help.

I overrid the ordering this way: {!{wpv-view name='postes' orderby='title@organisme-poste.parent'}!}

Seemed to work except for that Réplique Estrie parent post

#2835031

Minesh
Supporter

Languages: English (English )

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

I'm not sure if its going to work or not.

Can you please send me admin access details and tell me what is your expected order on the problem URL.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

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

#2835594

Minesh
Supporter

Languages: English (English )

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

Can you please check now:

I've added the view's filter hook "wpv_filter_query_post_process" to "Custom Code" section offered by Toolset:
=> hidden link

add_filter( 'wpv_filter_query_post_process', 'func_order_result_by_parent_post_title', 999, 3 );
function func_order_result_by_parent_post_title( $query, $view_settings, $view_id ) {
    
  if ( $view_id == 1315 ) { 
   
       
     
      $post_relationship_slug='organisme-poste';
       

       $all_posts = $query->posts;
             
       
      foreach($all_posts as $k=>$v):
      
           $get_parent =  toolset_get_related_post($v->ID,$post_relationship_slug);
           
             
               		$parent = get_post($get_parent);
                    $result[$v->ID] = $parent->post_title;
             
      endforeach;
    
    
    	$result = array_unique($result);
    	asort($result);
    	
    	$final_result = array();
    	foreach($result as $k=>$v):
    		$final_result[] = get_post($k);
    	endforeach;
    
    
    	 $query->posts = $final_result; 
        $query->found_posts = count($final_result); // modify the count of found posts
         $query->post_count = count($final_result); // modify the count of displayed posts
   
    
  }
    return $query;
}

More info:
- https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
- https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query_post_process
- https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/#adding-custom-php-code-using-toolset

#2835595

Thank you Minesh, You rock! (as always)