Skip Navigation

[Closed] Display list of parent posts

This support ticket is created 3 years, 10 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Author
Posts
#1669895

Hi,
I got a "schools" CPT and a "formations" child CPT.
I have an archive view displaying all formations based on several filters.
Top of the view, there is a map where I need to display "schools" that have "formations" returned by the querry.
That way, I will be able to load :
- a map of all schools ;
- for each school on the map, the list of formations (into a child view);
- a list of formations.
What would be the cleanest way to achieve this with Views ?
Thank you.

#1671423
Screen Shot 2020-06-21 at 4.01.18 PM.png

Hello, there's not a simple way to do this because you need to filter a list of parent post by child post fields. Here's how I would do it using Classic Views (not the block editor). You'll need at least 3 Views - two Formation Views and one School View.

1. Create a custom search View of Formation posts, and add all the front-end filters you want to include. Use the Loop Wizard to display the main Formation post list. This View should list all the Formations matching your custom search query.
2. Once this View is returning the correct results, duplicate it from the dashboard at Toolset > Views. Use the Loop Wizard button to redesign the loop. Choose "List with separators" as the loop style. In the loop, use a comma ( , ) as the separator and insert the Post ID field. Use the "edit" button to choose the parent School post ID (see edit-post-id.png). Delete all the other fields from the loop. Be sure "Disable the wrapping DIV around the View" is checked in the View editor. Place this View on the same page as the View of Formation posts. You should see a comma-separated list of School IDs. It's okay if there are duplicate IDs here.
3. Insert a Map shortcode in the same page as the Formation View.
4. Create a View of School posts. Add a Query Filter to filter by Post ID, set by a shortcode attribute "ids". In the loop, display the School title and insert a Map Marker using the address of this School as the location for the marker. Use a View shortcode to insert this Schools View on the same page as the map and Formation View, and use the View from #2 in the "ids" attribute. This will display a list of School posts filtered by the Formation filters, and will also display a marker on the map for each matching School. Example:

[wpv-view name="Schools by ID" ids="[wpv-view name='Duplicate Formation View from Step 2']"]

Inside the list of Schools, do you want to display ALL Formations, or just those that match the Query Filters? I'm not clear from your description if you want to display a list of ALL Formations for each School, as well as those matching the filters in a separate list?

#1671933

Thank you very much.
My main view is an archive view, with several filters.
Since it's an Archive, I wasn't able to duplicate, and therefore the list of schools isn't filtered by the Archive filters.
How may I apply the Archive filters to the list of schools query ?
Thank you.

#1672651

You can set up identical Query Filters in the View. If you cannot see the Query Filter panel, you must scroll to the top right corner and click Screen Options to show the Query Filter panel. Then you can create identical Query Filters, using the same URL parameters as needed.

#1672667

Hi,
I already did this but the list keep displaying ALL formations, whatever the filters are.
Thank you.

#1673593

I can take a closer look if you provide login credentials and show me where to find the View on the front-end of the site.

#1675231

Okay the Liste des établissements avec des formations View does not "listen" for changes in the WP Archive's filters, so it was not updating when the filters were changed. I have moved the Liste des établissements avec des formations View into the WP Archive's Loop editor, because this forces it to update whenever the filters are updated. I can see some changes now when I apply the "Formation initiale" Type filter.

Original results, reduced to unique IDs: (18) [209, 249, 256, 228, 236, 227, 200, 248, 246, 251, 242, 239, 238, 205, 268, 210, 211, 197]
Formation initiale type filter applied, then reduced to unique IDs: (7) [256, 236, 200, 242, 268, 210, 197]

Are these the results you expect to see when the "Formation initale" Type filter is applied?

#1675317

Thank you.
This solved part of the problem in deed. Now the filters work OK, but the querry filter based on what term is the Archive page still don't work.
For instance on hidden link, you can count 31 formations for 5 different schools (not 18).
When applying "Formation initiale" filter, I should have only 2 schools remaining (not 7).
Thank you.

#1676599

Yes, you are correct. WP Archives automatically filter based on the current archive term, but Views do not automatically filter based on the current archive term. You have added a Query Filter for the domaine term, set to respond to a URL parameter:

Select posts with taxonomy:
Domaines slug in one of those set by the URL parameter wpv-domaine
eg. <em><u>hidden link</u></em>"

However, no wpv-domaine URL parameter is added to the page. Since the View does not filter automatically, and no URL parameter is added, I do not expect the View will show filtered results. If you add the URL parameter manually, are the results accurate?
hidden link

If the results are accurate, then the problem is this term filter is not automatically applied to the View. You could reconfigure the filter to use a shortcode attribute instead of a URL parameter, then pass in the current archive's term slug using the wpv-taxonomy-archive shortcode: https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-taxonomy-archive
https://toolset.com/documentation/user-guides/views/passing-arguments-to-views/
This is probably the simplest solution that does not involve custom code.

#1676633

Hello and thank you very much, I see we're close now.
In deed hidden link shows the expected results.
Now I changed the View taxonomy arguments from url_parameters to shortcode attributes, then added those args to my view call, in the Archive :

[wpv-view name="liste-des-etablissements-avec-des-formations" view_display="layout" wpvdomaine="[wpv-taxonomy-archive info='slug']" wpvniveau="[wpv-taxonomy-archive info='slug']" wpvtype="[wpv-taxonomy-archive info='slug']"]

But nothing changes... Same wrong results, but hidden link still working...

#1682607

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Screenshot 2020-06-30 at 9.51.08 AM.png

Hi Roman,

As Christian is currently unavailable due to vacation I will be handling this ticket.

From what I can see you are filtering your taxonomy view on your Archive based on the Archive's slug. Confirming that you only want to display the information based on the current archive.

Meaning if you are on the Domaines archive you only want the view to filter for the Domaines and so on and so forth with the others correct?

If that is the case you will need to set the comparison logic to an OR instead of an AND.See Screenshot.

Edit the query filter and set it to OR.

Please let me know if this helps.
Thanks,
Shane

#1682761

Hello and thank you,

1- In deed, on the hidden link page, I need only formations with "Agroalimentaire" term to display.
That works.

2- Now, I have a second view, that should get IDs of all Schools with at least 1 formation with "Agroalimentaire" term.
That does not work, since you may see the list displays a lot more IDs than there is "Agroalimentaire" formations in the list.

3- After that, I also need the filters of the formations Archive view only to display choices where there is result. Meaning for instance on this page hidden link, the filters should only display 2 Etablissements in the Etablissements list.

4- Finally, the list of Shcools IDs must also be filtered by the dynamic filters in the Archive View. Meaning if I have the correct result at step 3, I will have 2 Etablissements in the IDs list; then if I choose one in the Etablissement filter, I will get only 1 ID in the list.

Thank you.

#1682905

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Roman,

Based on the assessment its seems that the taxonomy filter is being ignored by the view.

Would it be ok if I ran some tests by disabling a few of your plugins to see if any of them is interfering with the filters?

Thanks,
Shane

#1682957

Yes please

#1684303

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Roman,

The issue seems to be the view itself that you've added to the archive.

Can you remake this view below.
hidden link

When I created a separate test view, I noticed that the items filtered correctly with no issue. They are displaying the correct results.

However it should be noted that since you're getting the Parent ID with the view then you will have repeated ID's in the results since many of them share the same parent.

You can verify this by checking my test view here.
hidden link

If you modify the query filter you will notice that the results change.

Please let me know if this helps.
Thanks,
Shane

The topic ‘[Closed] Display list of parent posts’ is closed to new replies.