Accueil › Toolset Professional Support › [Résolu] Group by parent type
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.
Aucun de nos assistants n'est disponible aujourd'hui sur le forum Jeu d'outils. Veuillez créer un ticket, et nous nous le traiterons dès notre prochaine connexion. Merci de votre compréhension.
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)
Marqué : Views, Views plugin
Ce sujet contient 17 réponses, a 2 voix.
Dernière mise à jour par Franck Il y a 4 années et 10 mois.
Assisté par: Minesh.
Hi,
On this view : lien caché
i would like to group by result by parent post.
But i don't know how 🙁
I try with this but i don't really know if it possible : https://wordpress.stackexchange.com/questions/74798/posts-groupby-problem
Thanks for your help
Hello. Thank you for contacting the Toolset support.
I would like to know first, do you have any post-relationship between any of your post types? If yes, what is the relationship and what are the post types?
The link you shared I could not able to see it, Can you please send me access details.
*** 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.
Ok - I'm able to load the problem URL you shared with me and I see you have added the custom search with the map as well as you are displaying the results.
Now, as I understand, you want to display the results as:
- program One
-- Lot post 1
-- Lot post 2
-- Lot post 3
- program Two
-- Lot post 4
-- Lot post 5
-- Lot post 6
If the above example is correct - you can not group the posts by the parent as to display the posts group by a parent we need to use the nested view. One view that displays the parent (program ) information and one view to display the child (Lot) information and we need to add the child view inside the parent view's Loop.
With your current Lot view, you have added the custom search and map, if we create parent view and add the Lot view that you created within the parent view's Loop editor the custom search will be repeated with each parent view iteration that is why its not possible to use the nested view and display the lots group by parent.
However, if you just want to display the parent title just beside the lot title, that's possible.
Hi,
thanks for your answer.
No it is not exactly that.
I want
- program One
- program Two
- program Three
You will say ; Why i create a lot view ?
Answer : Because i need to filter on it.
So what is the best ?
Thanks a lot
do you mean that you want parent post as frontend select dropdown filter?
A don't understand your answer.
I mean : i need to filter child posts but i want parent post in result.
It is like i have room houses and rooms
I need to search all houses that have 3 rooms.
We can see, i filter on rooms but i display Houses.
I mean : i need to filter child posts but i want parent post in result.
==>
ok but you just want to display the associated parent post title to your related lot view? How exactly you want to display the parent?
We can see, i filter on rooms but i display Houses.
==>
There is no houses. I think I understand what you are saying but its still not clear to me and withount knowing what exactly you want to display at what place Its hard for me to guide you in the right direction.
Can you please share a few screenshots of how exactly you want to display the parent?
I mean : i need to filter child posts but i want parent post in result.
==>
ok but you just want to display the associated parent post title to your related lot view? How exactly you want to display the parent?
-----> Not just the title, i need all filed of the parent post
We can see, i filter on rooms but i display Houses.
==>
There is no houses. I think I understand what you are saying but its still not clear to me and withount knowing what exactly you want to display at what place Its hard for me to guide you in the right direction.
---> I wanted explain. Houses is like program and rooms like lot.
Can you please share a few screenshots of how exactly you want to display the parent?
I have no screen, but i can explain :
I need filter all programs that have child (lot) with parameter selected.
And i want display programs like title, picture and others fields.
I need filter all programs that have child (lot) with parameter selected.
==>
So, as I understand now, you want to display the parent (programs) information only, not the lot information?
I checked that following Lot posts have been assigned the value "Montpellier" with the field "Ville":
=> lien caché
=> lien caché
And the parent Program to both of the above post has been assigned as "Le Gabriel"
=> lien caché
Now, with your frontend custom search view, with the following link:
=> lien caché
- Do you want to display all the fields belongs to the parent post "Le Gabriel"?
If yes:
- Do you want to display the custom fields belong to a lot (child) as well or only program fields?
- Do you want to display only the parent post (Program ) field and the parent post should be displayed only once? because the view you created is set to query the Lot post type and it will return for the example the following two posts which are assigned with the same parent.
=> lien caché
=> lien caché
I see with your view you are already displaying the parent information:
[types field='nom-du-programme' item='@programme-lot.parent'][/types]
Is your concern is that the name of the program should not be repeated?
Now, with your frontend custom search view, with the following link:
=> lien caché
- Do you want to display all the fields belongs to the parent post "Le Gabriel"?
-->YES
If yes:
- Do you want to display the custom fields belong to a lot (child) as well or only program fields?
--> Parent filed
- Do you want to display only the parent post (Program ) field and the parent post should be displayed only once?
--> Yes
because the view you created is set to query the Lot post type and it will return for the example the following two posts which are assigned with the same parent.
=> lien caché
=> lien caché
--> Yes, i know it is that my problem 🙁
I see with your view you are already displaying the parent information:
1
[types field='nom-du-programme' item='@programme-lot.parent'][/types]
Is your concern is that the name of the program should not be repeated?
--> No my problem, as you have understood, is i need to group by program
Can you please check now: lien caché
I've added the following code to "Custom Code" section offered by Toolset:
=> lien caché
add_filter( 'wpv_filter_query_post_process', 'func_group_by_parent_post', 10, 3 ); function func_group_by_parent_post( $query, $view_settings, $view_id ) { if ($view_id == 35669 ) { $all_post_ids = array(); $all_found_posts = $query->posts; foreach($all_found_posts as $k=>$v): $parent = toolset_get_related_post( $v->ID,'programme-lot' ); $all_post_ids[$parent]= $v; endforeach; $query->posts = $all_post_ids; } return $query; }
I can see now its not returning the duplicate parent post.
Now, you can add whatever parent fields you want to display to your Loop Editor section.
=> lien caché
Hi Minesh,
YOu are really the best, but i think i have some problem right now 🙁
First, there is some errors that i didn't have before, i try to instal latest extension, but errors still be there.
I try to desactivate your code, the error is still there but it is strange because, me, i didn't change anything, do you have idea ?
Second, my jquery doesn't work anymore on the page. Maybe same problem ?
And i think there is a problem because when i add a city in filter "Montpellier" there are 4 results, and without city, there are 3 results, how it is possible 🙁
Thanks for your help.
First, there is some errors that i didn't have before, i try to instal latest extension, but errors still be there.
I try to desactivate your code, the error is still there but it is strange because, me, i didn't change anything, do you have idea ?
==>
The errors should be gone now, it was displaying because I've activated the debug mode which I disabled now.
Second, my jquery doesn't work anymore on the page. Maybe same problem ?
And i think there is a problem because when i add a city in filter "Montpellier" there are 4 results, and without city, there are 3 results, how it is possible
==>
Can you please tell me what ou mean by " i add a city in filter "Montpellier" there are 4 results, and without city, there are 3 results"
Yes no error anymore 🙂
But you can see lien caché
It is search without filter, i have 3 results
And with filter : lien caché
i have 4 results il is ont logical , no ?
I see you have thousands of lots and program entries added.
If you notice - with the following link - the parent IDs are 23998, 34829 and 23934 - I checked all these IDs are program (parent) IDs.
=> lien caché
Then, I checked by filtering the view with "Montpellier" and I see the program (parent) IDs 32737, 33179, 32735 and 33379. Again, I checked all these IDs are program (parent) IDs.
=> lien caché
So, I checked again and the code I added works as expected to return the unique parents.