• I have a custom post type called “wines”. Under the wines post type I have categories set up like: Reds, Whites, and Winemakers. Under the reds category, I have malbecs, merlot, zinfandel. Under the winemaker I have a few names that I would like to display.

    I’m trying to set up the archive page to show each taxonomy under a category. So like:

    WINES
    ——–
    Reds
    – Malbecs
    – Merlot

    Whites
    – Pinot Gris
    – chardonnay

    Winemakers
    – Makername 1
    – Makername 2

    How can I accomplish this?

    • This topic was modified 7 years, 1 month ago by harshclimate.
Viewing 5 replies - 1 through 5 (of 5 total)
  • hi
    what the problem do you have?
    with create deeplier categories or show the whole categories tree in the menu on the website?

    Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    @harshclimate I’ve removed your duplicate topic, please do not create duplicates.

    Moderator bcworkz

    (@bcworkz)

    Hello again ??

    You can get such a list by using wp_list_categories(). This works for other taxonomies besides categories by passing a “taxonomy” argument. By default each listed term is a link to an archive page for just that term.

    If your intention was to also list posts under each term, this isn’t an ideal function because you’d have to parse HTML to inject the post listings. It’s possible though. The alternative is to use get_terms(), then query posts for each term. With this you lose the handy hierarchical format used in the previous approach. You’d need to create it yourself. The source for wp_list_categories() could be a guide for doing this. The key is using walk_category_tree() to determine the proper hierarchy.

    On very large sites, querying for a set of posts for every term is very inefficient. It’d be better to query for all applicable posts, ordering by term. Then parse the returned posts into separate groups which can be rearranged into hierarchical order. This gets pretty advanced in the name of efficiency. Probably not required on most averaged sized sites. Querying posts by term is complicated enough.

    Honestly, I’d be satisfied with wp_list_categories() alone. I don’t see a big advantage to listing posts on the same page. The ones a user is interested in is just one click away. Then your server does not need to query for posts the user has no interest in.

    Thread Starter harshclimate

    (@harshclimate)

    That’s listing all the categories under my normal loop query, but not a cpt query, right?

    Moderator bcworkz

    (@bcworkz)

    Right. And the links it generates may lead to posts lists only, not CPTs. The links could be modified to include a post_type query string, or the query at the destination could be modified to include CPTs. There’s almost always a way to accomplish something. Some things are a lot harder than others though.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Trying to extract info from taxonomy’ is closed to new replies.