Hi,
Thank you for waiting, while I performed some tests on my website.
Here are the steps that I'll recommend:
1. Please create a taxonomy view to show the list of "Domaine" taxonomy terms, ordered by the "Post count".
( screenshot: hidden link )
2. In this view's "Query Filter" section, include taxonomy term filter, which is linked to the shortcode attribute "terms".
( screenshot: hidden link )
3. In the "Loop Editor" section, select the "List with separators" format for the loop and include the title and post count fields so that the complete code looks like this:
[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->
<wpv-loop>
[wpv-item index=other]
[wpv-taxonomy-title] ( [wpv-taxonomy-post-count] formations ),
[wpv-item index=last]
[wpv-taxonomy-title] ( [wpv-taxonomy-post-count] formations )
</wpv-loop>
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]
<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
[/wpv-no-items-found]
[wpv-layout-end]
4. Next, you'll need a custom shortcode, that can return the Term IDs attached to a post through its ID:
add_shortcode('get_attached_term_ids', 'get_attached_term_ids_func');
function get_attached_term_ids_func($atts) {
$a = shortcode_atts( array(
'id' => '',
'taxonomy' => '',
'seperator' => ', ',
), $atts );
$terms = get_the_terms( $a['id'], $a['taxonomy'] );
if ( $terms && ! is_wp_error( $terms ) ) {
$tax_ids = array();
foreach ( $terms as $term ) {
$tax_ids[] = $term->term_id;
}
$tax_ids_output = implode($a['seperator'], $tax_ids);
}
return $tax_ids_output;
}
The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through active theme's "functions.php" file.
5. After this, you'll create a new post view to show the "Formations" posts related to the "School" post where this view is shown.
( screenshot: hidden link )
7. In the "Loop Editor" section of this view too, select the "List with separators" format for the loop and include the custom shortcode registered in step 4, like this:
[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->
<wpv-loop>
[wpv-item index=other]
[get_attached_term_ids id="[wpv-post-id]" taxonomy="domaine"],
[wpv-item index=last]
[get_attached_term_ids id="[wpv-post-id]" taxonomy="domaine"]
</wpv-loop>
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]
<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
[/wpv-no-items-found]
[wpv-layout-end]
As a result, this view will cycle through all the related formation posts, and will only return the comma-separated list of the attached "Domaine" term IDs.
7. The last step would be placing the shortcode of the taxonomy view created in step 1, in the single School custom template and passing on the attached term IDs in a shortcode attribute "terms", using the view from step 5:
[wpv-view name="view-to-show-ordered-domaines" terms="[wpv-view name='view-to-get-related-formations-term-ids']"]
Note: You'll replace "view-to-show-ordered-domaines" with the slug of the view from step 1, and "view-to-get-related-formations-term-ids" with the slug of the view from step 5.
I hope this helps and please let me know if you need any further assistance around this.
regards,
Waqar