Passer la navigation

[Résolu] Displaying first and second level of a taxonomy

This support ticket is created Il y a 2 weeks, 1 day. 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 -

Fuseau horaire du supporter : Asia/Kolkata (GMT+05:30)

Ce sujet contient 4 réponses, a 1 voix.

Dernière mise à jour par shannonM-4 Il y a 1 week, 5 days.

Assisté par: Minesh.

Auteur
Publications
#2861514
Child view.png
Parent view.png
visual mockup.png

Hi there,

I'm trying to display a custom taxonomy (Services) for a custom post (Agency) using legacy Views. My custom taxonomy is caterogical and has two levels in its hierarchy (e.g., Health & Wellness > Emergency Medical Services). Please see the attached visual mockup for reference.

As stated, I'm trying to display a list of Agency custom posts and their associated Services taxonomy terms. I think I need to nest my views like so:

1. Parent view: list all Agency posts.
2. Child (nested) view: list all first-level taxonomy terms connected to the current Agency.
3. Grandchild (nested) view: list all second-level taxonomy terms connected to the parent term.

Assuming this structure is correct (and it may not be), I have been able to get the Parent view (#1) to work correctly, but I can't get the Child (nested) view (#2) to display any content. Please refer to the attached screenshots of the Views' configuration.

Can you offer any guidance?

Thank you.

Saul

#2861567

Minesh
Supporter

Les langues: Anglais (English )

Fuseau horaire: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Can you please share problem URL and admin access details and tell me what is your expected resunt under every section.

*** 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.

#2861706

Minesh
Supporter

Les langues: Anglais (English )

Fuseau horaire: Asia/Kolkata (GMT+05:30)

I see you have many-to-many post relationship between the post type Agencies and Programs.

But as you have many to many post reltionship. how you want to displau the Services taxonomy terms.

When you have many to many post relationship there is possiblility of having more than one related program post. So lets assume with the Agency post "Test Agency 1 (do not delete)" you have three related program post and you assigned taxonomy terms as given under:

Program post 1
- term 1
-- term 11
- term 2
-- term 22
program post 2
- term 3
-- term 33
- term 4
-- term 44
program post 3
- term 5
-- term 55

As you can see now, the terms are assiged per post. you want to display the parent and child term per post or all the terms altogather?

#2861734

Minesh,

Thanks for your response.

> ...the terms are assigned per post. you want to display the parent and child term per post or all the terms altogether?

I want to show the aggregated terms. To use a textual representation, as you did, here's what I'm looking for. If I have an Agency post connected to two Program posts with the following taxonomy terms:

Program Post 1
- Term 1
-- Term 1.1
- Term 2
-- Term 2.2

Program Post 2
- Term 1
-- Term 1.2
- Term 3
-- Term 3.1

Then I would want the terms to be displayed as follows:

Term 1
+ Term 1.1
+ Term 1.2

Term 2
+ Term 2.2

Term 3
+ Term 3.1

Does that make sense?

Saul

#2861856

Minesh
Supporter

Les langues: Anglais (English )

Fuseau horaire: Asia/Kolkata (GMT+05:30)

To your "View of Agencies' Services" view:
=> lien caché

I've added the following view to your abive view's loop template:

<h1> programs belongs to Agency </h1>
[wpv-view name="programs_belongs_agency"]>

Here is the "programs_belongs_agency" view:
=> lien caché

I've added the plugin code snippets and I've added the following custom shortcode to the following code snippet:
=> lien caché

function list_hierarchical_terms($atts) {
    global $post;
            
    $taxonomy = $atts['taxonomy']; 
    $separator = $atts['separator'];
    $terms = wp_get_object_terms( $post->ID, $taxonomy, array( "fields" => "ids" ) );
    if( $terms ) {
        $terms = trim( implode( ',', (array) $terms ), ' ,' );
        return wp_list_categories( 'title_li=&taxonomy=' . $taxonomy . '&include=' . $terms."&hierarchical=1"."&separator=".$separator."&echo=0&style=list");
           
    }
}
add_shortcode('display_post_tax_terms_hierarchical', 'list_hierarchical_terms');

To the "programs_belongs_agency" view I've added the following custom shortcode to the view's loop:

[display_post_tax_terms_hierarchical taxonomy="service" separator="<li>"]

Can you please check now: lien caché

I hope this solution will helpo you to resolve your issue.

#2861929

Thanks, Minesh! This did the trick. 🙂